https://kotlinlang.org logo
Docs
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
  • a

    amadeu01

    01/21/2019, 7:58 PM
    it seems that
    CoroutineScheduler
    uses
    require
    that uses
    contract
    which is experimental
    e
    • 2
    • 4
  • h

    Hauke Radtki

    01/21/2019, 9:18 PM
    Is there any way to obtain a this reference to a lambda from within itself? Usecase:
    val cb ={ event: SomeEventType ->
                     // Do stuff on event
                     callbackList.remove( /* How to obtain reference to self*/)
            }
            callbackList.add(cb)
            // Do stuff that will trigger cb in the list to be called
    Think of a list of one-time callbacks.
    h
    r
    • 3
    • 3
  • p

    pniederw

    01/22/2019, 1:16 AM
    my build has some "discoverMainScriptsExtensions" tasks (presumably added by Kotlin plugin) that are never UP-TO-DATE. what are those, and how can I get rid of them?
    a
    • 2
    • 10
  • u

    ursus

    01/22/2019, 6:24 AM
    but having basicailly a constant thrown locally feels weird, also a having it in baseUrl() function feels weird .. constant with %s and then string.format?
    k
    • 2
    • 2
  • n

    nkiesel

    01/22/2019, 8:36 AM
    I wanted to use "when with capture" in the following way:
    val b = when(val computed = f()) { computed > 0 -> computed + 1 ; else -> computed - 1 }
    but this produces a syntax error. Is the only way really to use
    val computed = f(); val b = when {  computed > 0 -> computed + 1 ; else -> computed - 1 }
    (with leaking of
    computed
    outside of the
    when
    scope)?
    a
    • 2
    • 2
  • p

    pniederw

    01/22/2019, 11:03 AM
    In other words, in which cases does a Kotlin library (not) expose
    kotlin-stdlib
    in its API?
    g
    • 2
    • 20
  • a

    amadeu01

    01/22/2019, 1:02 PM
    myObj?.let { myOtherObj.property = it }
    myObj?.let(myOtherObj.property::set)
    I was wondering. I just want to set a variable to other object property if my variable is not null. So, could a do something like above
    .let(myOtherObj.property::set)
    ?
    h
    • 2
    • 3
  • l

    LeoColman

    01/22/2019, 1:11 PM
    You can reference it's function, using
    myOtherObj::property::set
    , if I'm not mistaken
    ✔️ 1
    a
    • 2
    • 1
  • l

    LeoColman

    01/22/2019, 1:16 PM
    I believe that depends on Reflect tho
    a
    l
    • 3
    • 3
  • a

    amadeu01

    01/22/2019, 2:21 PM
    when will be channels a stable feature ?
    g
    • 2
    • 1
  • b

    bram93

    01/22/2019, 2:31 PM
    Is it possible to still benefit from the code completion; how can IntelliJ pick up that my .kts file is depending on some kind of DSL dependency?
    k
    • 2
    • 1
  • a

    arild

    01/22/2019, 4:39 PM
    Oh, and also, could you define a union type in Kotlin?
    h
    r
    k
    • 4
    • 3
  • l

    LeoColman

    01/22/2019, 4:47 PM
    Guys, I think I found a bug in Intellij + Kotlin. I reported it here: https://youtrack.jetbrains.com/issue/KT-29435
    h
    • 2
    • 7
  • b

    Bence Zsigmond Nagy

    01/22/2019, 7:59 PM
    How do Kotlin Inline classes compare to other languages' value types (e.g.
    struct
    in C#, Swift or even plain-old C)? I see there are a lot of similarities between the two concepts (let's say one is
    struct
    in Swift): they can implement interfaces/protocols, can have properties, methods, and both are allocated on the stack without any memory overhead (please correct me if I'm wrong). What are the differences other than Inline classes can only have one underlying primitive type?
    d
    o
    +3
    • 6
    • 7
  • n

    nikospamp

    01/22/2019, 9:48 PM
    Hello guys! I'm getting the following error when I'm converting an old JAVA class to kotlin: MutableLiveData<LiveDataRetrofitWrapper<?>> cannot be converted to MutableLiveData<LiveDataRetrofitWrapper> Here's where the error occurs:
    MutableLiveData<LiveDataRetrofitWrapper> reminders = mRepository.getImportantRemindersByTimestamp(token, timestamp);
    And the getImportantRemindersByTimestamp returns this:
    val data = MutableLiveData<LiveDataRetrofitWrapper<*>>()
    return data
    I can understand the error, but I have no idea how to fix it. Thanks!
    p
    t
    • 3
    • 5
  • d

    Dalinar

    01/23/2019, 5:43 AM
    is it bad form to put a companion object at the top of a class? I always put them at the bottom but for this file, the top is nice
    n
    a
    +4
    • 7
    • 6
  • d

    Dalinar

    01/23/2019, 8:29 AM
    is
    x as String
    essentially the same thing as doing
    (x as String?)!!
    ?
    g
    • 2
    • 6
  • d

    Dalinar

    01/23/2019, 9:26 AM
    so, let me see if I got constructors straight... 1. if you have a single constructor then
    ()
    after the classname is not required... 2. however if you have secondary constructors then it is now required 3. and now you might also want to make that constructor private
    g
    h
    +4
    • 7
    • 23
  • m

    maxmello

    01/23/2019, 9:56 AM
    I had a weird bug today regarding
    when
    . I have a field that holds an enum value and in another place, I have an (exhaustive) when given that field. So the parameter of the
    when
    was of type
    T
    . Then, I changed the field to be instead a
    LiveData<T>
    . A lot of places in my source threw errors and I fixed them by calling
    .value
    on the field. But the
    when
    did not threw an error (as the when does not return anything, the fact that is is no longer exhausive is not an error). But why can I even write:
    when(status /* type = LiveData<T>*/) {
       T.FIRST_VALUE -> { ... }
       T.SECOND_VALUE -> { ... } 
       T.THIRD_VALUE -> { ... }
    as status can never be any of these types? When I try the same structure with a String as parameter, it throws an error (incompatible types).
    d
    • 2
    • 5
  • j

    jasondlee

    01/23/2019, 2:50 PM
    I'm porting java to kotlin. i have an interface with a default method. what's the kotlin equivalent of that?
    r
    d
    • 3
    • 5
  • m

    marlonn

    01/23/2019, 3:11 PM
    everyone knows if there is a variable declaration standard for kotlin ?
    🥔 1
    m
    s
    +2
    • 5
    • 15
  • i

    Icaro Temponi

    01/23/2019, 3:43 PM
    Is kotlinx.serialization stable and performatic enough to be used on production?
    e
    • 2
    • 2
  • a

    amadeu01

    01/23/2019, 4:31 PM
    hi guys, is it possible to make "copy" of
    list
    like
    data classes
    and then change one of its elements? Something like
    var list = List<MyObj>
    list = list.copy(element = myObj(), index = 3)
    h
    • 2
    • 1
  • j

    jw

    01/23/2019, 4:34 PM
    https://youtrack.jetbrains.com/issue/KT-25617
    👍 8
    m
    z
    • 3
    • 5
  • a

    Andrew Gazelka

    01/23/2019, 5:50 PM
    for constructors one must initially reference
    this(...)
    . However, sometimes it requires a bit of code to transform parameters to
    ...
    . Should I... 1) have a separate function which acts as a static constructor 2) have the constructor of the class reference a function
    a
    d
    • 3
    • 50
  • u

    user

    01/23/2019, 7:18 PM
    message has been deleted
    🎉 16
    :kotlin: 1
    c
    • 1
    • 2
  • u

    user

    01/23/2019, 7:53 PM
    Kotlin 1.3.20 released We’re happy to announce the release of Kotlin 1.3.20, a new bug fix and tooling update for Kotlin 1.3. In addition to improvements to the compiler and IDE, this version: Allows running Gradle tasks in parallel within a single project … Continue reading →
    🎉 4
    :gradle: 1
    g
    • 1
    • 1
  • x

    xenoterracide

    01/23/2019, 7:54 PM
    in a constructor is it possible to say that the default value for something if not defined is the result of a function?
    👍 1
    p
    • 2
    • 6
  • t

    tateisu

    01/23/2019, 8:08 PM
    https://gist.github.com/tateisu/d47dd733cba989adc138f1827236f709 I have experience build error on kotlin 1.3.20 .
    t
    c
    • 3
    • 12
  • x

    xenoterracide

    01/23/2019, 8:19 PM
    how do I achieve this as a telescoping constructor? (this doesn’t compile)
    class PhgEdsClient : Consumer<EngDataStructure> {
        val mqttClient: MqttClient
    
        constructor( serverUri : String ) {
            mqttClient = {MqttClient(serverUri, PhgEdsClient::class.simpleName, MemoryPersistence())}()
        }
        constructor( val mqttClient: MqttClient)
    other variation, that doesn’t compile
    class PhgEdsClient( val mqttClient: MqttClient ) : Consumer<EngDataStructure> {
    
        constructor( serverUri : String ) {
            this(MqttClient(serverUri, PhgEdsClient::class.simpleName, MemoryPersistence()))
        }
    s
    • 2
    • 1
Powered by Linen
Title
x

xenoterracide

01/23/2019, 8:19 PM
how do I achieve this as a telescoping constructor? (this doesn’t compile)
class PhgEdsClient : Consumer<EngDataStructure> {
    val mqttClient: MqttClient

    constructor( serverUri : String ) {
        mqttClient = {MqttClient(serverUri, PhgEdsClient::class.simpleName, MemoryPersistence())}()
    }
    constructor( val mqttClient: MqttClient)
other variation, that doesn’t compile
class PhgEdsClient( val mqttClient: MqttClient ) : Consumer<EngDataStructure> {

    constructor( serverUri : String ) {
        this(MqttClient(serverUri, PhgEdsClient::class.simpleName, MemoryPersistence()))
    }
s

stephan_marshay

01/23/2019, 8:25 PM
https://kotlinlang.org/docs/reference/classes.html See
Secondary Constructors
View count: 1