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
  • b

    basher

    02/10/2019, 5:37 PM
    Is there a roadmap or plans for Kotlin to improve generics (breaking with Java)?
    c
    n
    +2
    • 5
    • 63
  • r

    reik.schatz

    02/11/2019, 1:00 PM
    val items = Arrays.asList("a", "b", "c")
    // doesn't compile because it is Stream<String?>!
    val stream: Stream<String> = items
        .stream()
        .map { item ->
           // call that returns nullable, i.e. String?
        }
        .filter(Objects::nonNull)
    u
    h
    • 3
    • 5
  • u

    utikeev

    02/11/2019, 1:20 PM
    Hello. I have this class where I’ve got some properties which should act both lazy and observable (so none of delegates suits me). What is the Kotlin-way I can get rid of the boilerplate on
    name
    and
    age
    variables?
    -.kt
    p
    j
    • 3
    • 5
  • t

    thana

    02/11/2019, 4:04 PM
    something is constantly removing the
    Target Platform
    from the Kotlin facet in my intellij instance which results in annoying reports from kotlin that somthing isn't availble on platform 1.6
    m
    • 2
    • 2
  • t

    tekjar

    02/11/2019, 5:50 PM
    Can someone please point me to an example of decompressing a zlib file idiomatically
    k
    • 2
    • 10
  • d

    dumptruckman

    02/11/2019, 8:08 PM
    Anyone know a way to make this more clear and concise?
    var talentName: String = NameDisplayFormatterFactory.getNameFormatterInstance(SPACE_DELIMITED_FORMATTER, locale)
                          .formatName(talent.firstName, talent.middleName, talent.lastName, talent.nameTitle, talent.nameSuffix)
                talentName = if (order.w2Order.orElse(false)) order.icName.orElse(talentName) else talentName
    a
    • 2
    • 1
  • x

    xenoterracide

    02/11/2019, 8:55 PM
    @Value("${spring.artemis.host}:${spring.artemis.port}"
    kotlin says string must be a compile time constant, this should be valid in java, how do I write it in kotlin?
    m
    • 2
    • 1
  • v

    Viet Hoang

    02/12/2019, 1:46 AM
    Hello, does anyone know the difference between
    ::class
    and
    .javaClass.kotlin
    ? And why is that in below example, the later declaration works but the prior doesn’t ?
    class Test {
        fun testMethod() {
            this::class.memberProperties.forEach { println(it.get(this)) } // compile error 
            this.javaClass.kotlin.memberProperties.forEach { println(it.get(this)) }
        }
    a
    • 2
    • 4
  • k

    Kulwinder Singh

    02/12/2019, 7:09 AM
    Hello all, i have very general question that is it safe to use
    inline
    classes in production android app ?,because its in experimental
    g
    l
    +4
    • 7
    • 16
  • l

    landoulsi

    02/12/2019, 7:59 AM
    Hey guys, I have a problem: after I migrated to the new multiplatform plugin, I am not able to use
    Mockk
    library on the common module test:
    MyTest.kt: (74, 9): Unresolved reference: every
    , does any one can help with this ?
    p
    • 2
    • 1
  • k

    karelpeeters

    02/12/2019, 9:56 AM
    Default arguments are faked via an extra function or constructor with an extra
    Int
    as the first argument that's basically a bitset of parameters that were actually passed.
    e
    • 2
    • 6
  • a

    arve

    02/12/2019, 10:04 AM
    I often come across a situation where i fetch some data class, process a field, then return the result. A contrived example:
    fun getFilm(title: String): Film {
        val data = db.getFilm(title)
        return data.copy(actors = data.actors.filterNot { it.isDead) })
    }
    Is there a way to avoid the temp variable without hitting the db twice? Or put differently, is there a way of referencing the source object in a copy operation somehow? Ideally I'm looking for something like
    fun getFilm(t: String) = db.getFilm(t).copy(actors = actors.filterNot { it.isDead })
    I'm aware of
    with
    , but in cases like this,
    with
    feels even more convoluted.
    t
    • 2
    • 1
  • g

    gildor

    02/12/2019, 10:09 AM
    run is fine name, it converts one value to another. And this is not about naming, you can add any alias to run, but it still will be better imo to use local variable
    k
    • 2
    • 4
  • e

    elect

    02/12/2019, 10:09 AM
    another thing: I find myself often in the situation where I do need a
    lateinit
    on inline classes (which is forbidden) which workarounds exist other than nullability?
    g
    • 2
    • 9
  • d

    Davide Giuseppe Farella

    02/12/2019, 10:20 AM
    Basically I got an Android lib where users can create a Drawer menu, 99% of the user will download the lib for the Drawer, but they also can add other `Panel`s, I dont wanna 1 force the user to use
    drawer = Panel()
    2 I don’t wanna leave
    Panel
    open only for
    class Drawer(): Panel()
    k
    • 2
    • 4
  • t

    thana

    02/12/2019, 10:39 AM
    a method expects as argument something like
    (String) -> Any
    . Shouldnt it be possible then, to pass
    this::someMethod
    if it takes a string and returns something?
    g
    j
    • 3
    • 5
  • j

    jw

    02/12/2019, 4:18 PM
    val sPayload = payload?.let(::String)
    👍 2
    t
    t
    k
    • 4
    • 9
  • a

    Andrew Gazelka

    02/12/2019, 5:48 PM
    iyo does it make sense to have classes which should probably be immutable mutable to make database management easier? for example... let's say I am using MongoDB with POJO mapping... if I have a complex immutable class it will be a pain to make a copy of it...
    m
    • 2
    • 3
  • g

    GarouDan

    02/12/2019, 6:43 PM
    Hi guys, I would like to build a kotlin mpp project with circleci. Someone knows which configuration can I put on my
    .circleci/config.yml
    file to put it to work?
    version: 2
    jobs:
      build:
        docker:
          - image: circleci/<language>:<version TAG>
        steps:
          - checkout
          - run: ./gradlew clean build
    Specially I don’t know what I could use in the place of:
    docker:
          - image: circleci/<language>:<version TAG>
    Does anyone have a suggestion of a pre-build docker image or some other configuration?
    g
    j
    d
    • 4
    • 8
  • s

    SOFe

    02/13/2019, 6:47 AM
    Is CLion still needed for Kotlin/Native to WebAssembly development? I saw a lot of articles that say so, including some from JetBrains websites, but I no longer see Kotlin/Native plugin in CLion 2019 EAP, and there is a Kotlin/Native template in IntelliJ IDEA. So are those articles outdated?
    a
    • 2
    • 6
  • h

    Hexa

    02/13/2019, 5:23 PM
    i fixed the above by changing data class to
    data class Message(val message: String? = null)
    j
    d
    • 3
    • 3
  • m

    M Jones

    02/13/2019, 9:51 PM
    @channel Hi folks, I just used the Spring BeanDefinitionDSL for kotlin. I was just wondering, how do I include an existing XML spring configuration in this?
    😱 1
    🙉 1
    📢 4
    r
    • 2
    • 2
  • j

    jw

    02/13/2019, 9:55 PM
    You just tried to notify 20,000 people. That's basically a sports arena full of people.
    💤 1
    😂 11
    y
    • 2
    • 1
  • m

    M Jones

    02/13/2019, 9:57 PM
    Wow, sorry @jw, I'll be more careful next time
    m
    • 2
    • 1
  • p

    pavel

    02/13/2019, 11:58 PM
    which, of course, works
    g
    s
    • 3
    • 7
  • j

    Joe

    02/14/2019, 1:15 AM
    what's an idiomatic way to get a list that has a single element prepended to an existing list. I've been doing:
    listOf(listOf(newElement), existingList).flatten()
    but that's a bit cumbersome. realized I can do
    listOf(newElement).union(existingList)
    , but that gives a
    Set
    instead of a
    List
    , which isn't always desired.
    n
    • 2
    • 2
  • p

    PHondogo

    02/14/2019, 5:13 AM
    Hi, guys! I have, for example, 'expect fun test() : Unit' and i want specify default actual for it, so in case there is no actual for any platform this implementation should be substituted. Does Kotlin have such possibility?
    h
    r
    • 3
    • 4
  • s

    sitepodmatt

    02/14/2019, 5:18 AM
    Is there any movement on plans for GADTs. Or is there a better way of representing lets say an unknown json payload Map<String, Any?> where Any? can recursively be Map<>, String, Integer, Float, Boolean etc..
    k
    • 2
    • 1
  • s

    safa

    02/14/2019, 12:09 PM
    Hello, a Kotlin/Native question: is it possible to have a shared .so KN runtime? Under the hood, I see program.bc runtime.bc and hello.bc being combined and linked. Our project needs to generate a lot of shared libs for interop and runtime loading, and it quickly grows in size considering the same stuff being put into all of them. Ideally I'd look into generating a shared runtime and lightweight libraries that are dynamically linked to that. moved to #kotlin-native
    o
    • 2
    • 1
  • c

    carlos cdmp

    02/14/2019, 12:39 PM
    I have a question, when you define a inner private object like
    class A{
        private object O{
            const val someConstant = 1
        }
    }
    The object has some kind of lifecycle attached to the A class or is it created at the beggining no matter if A will be created or not?
    g
    k
    • 3
    • 4
Powered by Linen
Title
c

carlos cdmp

02/14/2019, 12:39 PM
I have a question, when you define a inner private object like
class A{
    private object O{
        const val someConstant = 1
    }
}
The object has some kind of lifecycle attached to the A class or is it created at the beggining no matter if A will be created or not?
g

gildor

02/14/2019, 1:24 PM
There is no lifecyle, O is a singleton and has static field under the hood with instance of this companion object
c

carlos cdmp

02/14/2019, 2:43 PM
ok thanks, I supposed that but wanted to make sure 🙂
k

karelpeeters

02/14/2019, 3:20 PM
But in practice if you put some side effect code in
init
of course it runs at some point and so there's a lifecycle.
I don't know whether Kotlin or even the JVM guarantees anything about it though.
View count: 2