https://kotlinlang.org logo
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
announcements
  • u

    user

    10/02/2018, 9:22 AM
    message has been deleted
    🔥 5
    r
    v
    +2
    • 4
    • 7
  • f

    Fré Dumazy

    10/02/2018, 11:50 AM
    Can I build my kotlin projects with jdk11 on my machine? or does it only work with jdk8
    a
    • 2
    • 3
  • p

    pablisco

    10/02/2018, 12:29 PM
    In Kotlin, do we have a way (or a KEEP) to be able to define a Java Method as a getter without the prefix
    get
    ?
    y
    a
    +2
    • 5
    • 13
  • m

    miha-x64

    10/02/2018, 8:31 PM
    Why
    kotlinc
    generates
    somePropertyName$annotations()
    with annotations instead of putting them onto the backing field?..
    e
    o
    • 3
    • 6
  • h

    Hexa

    10/02/2018, 11:56 PM
    does anyone know how to fix
    Error:(33, 76) Kotlin: Unresolved reference: messageIndex
    in this line here? https://gist.github.com/rinnegan/878a8451bbae54441a588e75a5acbacd#file-group-by-messageindex-L33 . I want to group by
    MessageIndex
    . Code does not work if I remove
    val messageIndex: MessageIndex
    from this class
    data class MessageSender(
            val message: String
    
            //, val messageIndex: MessageIndex
    )
    n
    • 2
    • 1
  • h

    hamid.s

    10/03/2018, 7:02 AM
    Do we need {} in if? When it is only one operator, should I add {} after if? Here is a sample: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { window.statusBarColor = Util.getColor(R.color.accent_color) }
    a
    • 2
    • 1
  • b

    BorzdeG

    10/03/2018, 11:59 AM
    Tell me, what is not configured in the project https://github.com/BorzdeG/example-hello-multiplatform? When I run “./gradlew clean check” I get the error:
    > Task :hello-other-common:jar
    e: .../hello-other-jvm/src/main/kotlin/hello/other/jvm/HelloOtherData.kt: (3, 21): Unresolved reference: HelloCommonData
    e: .../hello-other-jvm/src/main/kotlin/hello/other/jvm/HelloOtherData.kt: (5, 48): Unresolved reference: HelloCommonData
    > Task :hello-other-jvm:compileKotlin FAILED
    At the same time, there are no errors in IDEA - only during the execution of the code.
    b
    n
    • 3
    • 9
  • h

    Hamza

    10/03/2018, 2:11 PM
    im sick of maven now so often whenever i set a program, it can’t read my dependencies. it happens so often and im so annoyed. why does this happen? This happens more often than not, im not sure why. someone please help me resolve tihs issue permanently
    :gradle: 5
    r
    d
    • 3
    • 12
  • h

    hallvard

    10/03/2018, 2:34 PM
    I'm multiplatforming (and it seems to work!), but I would like to declare an `expect`ed init block and can't seem to get the syntax right. Anyone care to give me an example or point me in the right direction?
    k
    • 2
    • 7
  • s

    Slackbot

    10/03/2018, 3:32 PM
    This message was deleted.
    s
    t
    • 3
    • 2
  • h

    Hexa

    10/03/2018, 3:34 PM
    does anyone know how to fix this syntax error? I want to alter the structure of the first map so that it returns
    List<Pair<PublisherMessage, deviceType>>
    . It currrently only returns
    emailMesssages: List<MessageSender>
    s
    i
    • 3
    • 25
  • w

    wei

    10/03/2018, 4:44 PM
    I have a list of keys
    keys
    and another map of key -> value
    map
    , whose keys are a subset of
    keys
    and whose value is either
    SOFT_DELETED
    or
    NOT_DELETED
    . For example:
    val keys = listOf("key1", "key2", "key3")
    val map = mapOf("key1" to "SOFT_DELETED", "key2" to "NOT_DELETED")
    I need to combine
    keys
    and
    map
    to generate another map
    finalMap
    , whose keys will contain all keys from
    keys
    that are not in keys of
    map
    with values of
    DELETED
    and keys of
    map
    that has a value of
    SOFT_DELETED
    . In the above example, I’d have:
    val finalMap = mapOf("key1" to "SOFT_DELETED", "key3" to "DELETED")
    I can think of mapping over
    keys
    and check each key against
    map
    and generate
    finalMap
    , like:
    val finalMap = keys.mapNotNull {
      when(map[it]) {
        "SOFT_DELETED") -> it to "SOFT_DELETED"
        null -> it to "DELETED"
        else -> null
      }
    }
    Is there a more idiomatic way in kotlin to do this?
    e
    • 2
    • 2
  • k

    karelpeeters

    10/03/2018, 4:55 PM
    keys.associate { it to "DELETED" } + map.filter { (k, v) -> v == "SOFT_DELETED" }
    w
    • 2
    • 4
  • m

    Mike

    10/03/2018, 5:47 PM
    Question regarding Null annotation support. When originally announced (https://blog.jetbrains.com/kotlin/2015/04/upcoming-change-more-null-safety-for-java/), support for javax.validation.constraints was listed. In some generated code, it has the javax.validation.constraints.NotNull annotation BUT IntelliJ and Kotlin aren't correctly detecting it. If I modify the generated code to use either org.jetbrains.annotations.NotNull or org.springframework.lang.NonNull or javax.annotation.Nonnull, they all work as expected. Was it decided to not include javax.validation.constraints in the list after all, or have I potentially found an issue? I haven't been able to find anything concrete on this topic so hoping someone here can provide some clarity.
    d
    h
    • 3
    • 5
  • s

    Slackbot

    10/03/2018, 6:10 PM
    This message was deleted.
    :stackoverflow: 1
    a
    i
    a
    • 4
    • 5
  • v

    ValV

    10/03/2018, 7:44 PM
    Why equality checks are preferable over elvis operator in case, when a boolean variable is nullabe? E.g.
    val parameter: Boolean? by param()
    if (parameter != false) ...
    instead of
    val parameter: Boolean? by param()
    if (parameter ?: true) ...
    👍 2
    d
    k
    • 3
    • 11
  • j

    jdemeulenaere

    10/03/2018, 7:56 PM
    It would be nice to have official support of Bazel to compile Kotlin, in my experience it makes building and testing much faster than with gradle. I know there are some already some rules by the Bazel team but I don't think they support multiplatform targets and the different compiler plugins. (Just a thought 🙂 )
    ➕ 1
    t
    m
    • 3
    • 5
  • d

    digitalsanctum

    10/03/2018, 10:01 PM
    Any recommendations for a library that makes creating a cli with Kotlin easy? I'm aware of a few in Java land but looking for alternatives
    d
    j
    +3
    • 6
    • 7
  • v

    Viral Thakker

    10/04/2018, 6:21 AM
    Hi everyone, Can anyone tell me why should we use kotlin instead of Java in business application?
    h
    e
    +3
    • 6
    • 24
  • m

    molikto

    10/04/2018, 7:15 AM
    I found I write code like this very often, a private mutable object and a public facing immutable api. is anyway to do it more elegantly in Kotlin? does it worth as a syntax sugar?
    👍 1
    k
    • 2
    • 3
  • q

    qwert_ukg

    10/04/2018, 8:34 AM
    I have a builder for my HTML layout and use it in my controllers. I want encapsulate a
    render
    function into my API file and don't want to provide an possibility to call it from builder
    s
    d
    • 3
    • 3
  • b

    Bernhard

    10/04/2018, 10:37 AM
    what annotation target is equivalent to the java TYPE_USE
    d
    • 2
    • 1
  • b

    bod

    10/04/2018, 11:55 AM
    Hello, World! I’m in a
    when (e)
    , (with e being an instance of
    MyEnum
    ) and for the branches, I’m allowed to put something that is not one of the possible values of
    MyEnum
    (I can put values of other enums). I find this extremely surprising 🙂 Thoughts?
    h
    a
    m
    • 4
    • 18
  • u

    Uzi Landsmann

    10/04/2018, 3:04 PM
    Hello Kotlin experts! We have a mixed Kotlin/Java project and would like to create data classes defined in Kotlin and use them in our Java code. We like using builders in our code and have used Lombok quite extensively in the past. My question is if there is a way to create automatic builders for Kotlin data classes (like Lombok does for Java classes) to avoid all the boilerplate of writing them by hand. Any suggestions?
    s
    h
    d
    • 4
    • 5
  • s

    Sam

    10/04/2018, 4:08 PM
    Is there a way to use lambda when dealing with abstract classes? object works but can't use lambda. DialogInterface.OnClickListener is an interface with SAM, BroadcastReceiver is an abstract class with SAM.
    private val listener = DialogInterface.OnClickListener { _, _ -> println("interface lambda") }
        private val listener1 = BroadcastReceiver { _, _ -> println("abstract class lambda") } // Error cannot create an instance of abstract class
    d
    a
    +2
    • 5
    • 15
  • h

    Hexa

    10/04/2018, 7:46 PM
    My Intellij is suggesting to add a .
    asSquence
    before calling
    groupBy
    on this function that I wrote, but I can't find any evidence to prove if this is a good idea or not. I wonder if anyone here can suggest if this is a good idea. So basically here is what the code look like
    //BEFORE adding.asSequence()
    
                            override fun handle(event: List<String>): Either<Errors.RequestError, Pair<List<Errors.RequestError>, Int>> =
                emailParser.parseEmails(event)
                        .map {
                            Pair(
                                    first = it.first,
                                    second = it.second
                                            .groupBy { it.emailAdrress }
                                            .map {
                                                Pair(
                                                        first = MessageDestination(it.key),
                                                        second = it.value.map {
                                                            MessageSender(
                                                                    message = it.environment
                                                            )
                                                        }
                                                )
                                            }.toMap()
                            )
                        }.flatMap { pair ->
                            service.handleRequests(pair.second)
                                    .map {
                                        Pair(pair.first, pair.second.size)
                                    }
                        }
    
    
    
    
     //AFTER adding .asSequence()
       override fun handle(event: List<String>): Either<Errors.RequestError, Pair<List<Errors.RequestError>, Int>> =
                emailParser.parseEmails(event)
                        .map {
                            Pair(
                                    first = it.first,
                                    second = it.second
                                            .asSequence()
                                            .groupBy { it.emailAdrress }
                                            .map {
                                                Pair(
                                                        first = MessageDestination(it.key),
                                                        second = it.value.map {
                                                            MessageSender(
                                                                    message = it.environment
                                                            )
                                                        }
                                                )
                                            }
                                            .toList().toMap()
                            )
                        }.flatMap { pair ->
                            service.handleRequests(pair.second)
                                    .map {
                                        Pair(pair.first, pair.second.size)
                                    }
                        }
    m
    s
    d
    • 4
    • 11
  • h

    Hullaballoonatic

    10/04/2018, 8:27 PM
    also can you think of a more succinct way to reference the class of a property than
    foo::class
    , and
    KClass<Bar>
    ?
    k
    • 2
    • 14
  • d

    Dominaezzz

    10/04/2018, 8:35 PM
    Why isn't the compiler happy with
    val num: UInt = 5
    ?
    h
    • 2
    • 5
  • s

    Sam

    10/04/2018, 8:53 PM
    Is this style of using apply and run recommended?
    IntentFilter().apply {
                    addAction( packageName +  INTENT_ACTION_OPEN )
                    addAction( packageName +  INTENT_ACTION_CLOSE )
                }.run {
                    registerReceiver( receiver, this )
                }
    d
    • 2
    • 10
  • h

    Hullaballoonatic

    10/04/2018, 9:16 PM
    what are the chances we will be given the ability to add custom operators? i'm guessing low to impossible given the existence of infix
    k
    m
    • 3
    • 12
Powered by Linen
Title
h

Hullaballoonatic

10/04/2018, 9:16 PM
what are the chances we will be given the ability to add custom operators? i'm guessing low to impossible given the existence of infix
k

karelpeeters

10/04/2018, 9:17 PM
See scala for how this tends do go wrong.
h

Hullaballoonatic

10/04/2018, 9:18 PM
is it mostly just a case of misuse? unreadable code?
k

karelpeeters

10/04/2018, 9:19 PM
Yeah. Here's a classic example: http://www.scala-graph.org/guides/core-initializing.html
m

Mike

10/04/2018, 9:20 PM
Or look at SBT. Until you know it, the operators feel random.
h

Hullaballoonatic

10/04/2018, 9:42 PM
do you think kotlin shouldn't employ features that can be used sloppily? i feel like it's a bit late for that with extension functions and properties.
i love kotlin because it can be written as to be supremely readable, and i think custom operators have the potential to improve that aspect, and i'm willing to see any feature capable of that, even if it can be greatly misused to the opposite effect
m

Mike

10/04/2018, 10:35 PM
Of course not. Great code can be written in any language, just like terrible code can be written in any language. I’m happy with Kotlin’s overloaded limited operators. But yes, any feature, when used well, can improve things. So it comes down to the team…
➕ 1
h

Hullaballoonatic

10/04/2018, 10:38 PM
honestly, one thing i'm most eager for is the further establishment of Kotlin codestyle, like how best to write chained scope functions, where if/else is appropriate to forego brackets, at what point should a single line property definition be split up, etc
m

Mike

10/04/2018, 11:24 PM
chained scope style is definitely a biggie. Makes such a difference in reading if it’s the way ‘you’ expect it to be vs when it isn’t. I don’t think the IntelliJ formatter provides quite enough control over formatting of things like that, although I haven’t looked super close. Also, on topic of operators, I’m curious about some examples as it would appear you have some ideas already. I was very glad to see they allowed overriding the arithmetic operators, as there are many cases where being able to do that cleans up code while keeping it feeling ‘natural’.
h

Hullaballoonatic

10/04/2018, 11:44 PM
One cool example is the
d
operator in D&D.
1d10+5
. I know infix does that, but I don't like the spaces. We could also create our own mathematical operators like a power operator
**
m

Mike

10/04/2018, 11:57 PM
Hmmm. I suspect another reason would be the impact on the compiler. Parsing that
d
out makes parsing take longer. Kotlin is already slower than Java, and a lot of people complain about Scala’s compiler speed. If you use the language, you stop caring, or don’t notice, but when you’re first starting out…
It’s a tough call designing a language. Glad I’m not doing it 😉
View count: 3