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

    Jgafner

    07/16/2021, 6:36 AM
    Hi Is it bad practice to have a parent interface for common property of data classes ? I found this in stack overflow and wondering if there is a official documentation about ti https://stackoverflow.com/questions/26444145/extend-data-class-in-kotlin
    c
    • 2
    • 3
  • p

    Pitel

    07/16/2021, 9:30 AM
    WTF?
    g
    d
    f
    • 4
    • 25
  • a

    Ayfri

    07/16/2021, 11:44 AM
    https://www.steamdeck.com/en wow
    :nospam: 4
    :not-kotlin: 6
    c
    • 2
    • 1
  • j

    jeggy

    07/16/2021, 12:06 PM
    I remember reading emoji support in intellij some time ago. Is it something I need to configure correctly to make it to work?
    a
    f
    • 3
    • 4
  • u

    user

    07/16/2021, 1:03 PM
    Useful Kotlin Idioms You Should Know Kotlin was designed to be very similar to Java to make migration as smooth as possible. However, Kotlin was also designed to improve the developers’ experience by providing a more expressive syntax and a more sophisticated type system. To take full advantage of the language and write more concise code, learning Kotlin idioms is a […]
    o
    • 1
    • 1
  • o

    Omkar Amberkar

    07/16/2021, 3:15 PM
    Hey, I am trying to create a polling mechanism using
    sharedflow
    which would be eventually replaced by network call polling every few seconds. This is what I am got so far but still not what I expect, my expectation 1. Start polling once at least one terminal operator is present
    collect
    2. Stop polling when no terminal operator 3. Share same value across all the terminal operator
    collect
    , but as you can see, the values are different. Also to add, when I
    cancel
    a
    pollingScope
    , the
    send
    function is still called since the flow is active and keeps throwing
    exception
    due to job cancellation. Help much appreciated!!!
    @ExperimentalCoroutinesApi
        fun poll(scope: CoroutineScope) = callbackFlow {
            invokeOnClose { Timber.e("Debug: channel closed") }
            while (true) {
                try {
                    val nextInt = Random.nextInt(0, 100)
                    Timber.e("Debug: nextInt -> $nextInt")
                    send(nextInt)
                    delay(MIN_REFRESH_TIME_MS)
                } catch (throwable: Throwable) {
                    Timber.e("Debug: error -> ${throwable.message}")
                }
            }
        }.shareIn(scope = scope, replay = 1, started = SharingStarted.WhileSubscribed())
    pollingScope.launch {
                    engine.poll(applicationScope).collect {
                        Timber.e("Debug: collect 1 -> $it")
                    }
                }
                pollingScope.launch {
                    engine.poll(applicationScope).collect {
                        Timber.e("Debug: collect 2 -> $it")
                    }
                }
                pollingScope.launch {
                    engine.poll(randomScope).collect {
                        Timber.e("Debug: collect 3 -> $it")
                    }
                }
    $poll: Debug: nextInt -> 59
    $poll: Debug: nextInt -> 68
    $poll: Debug: nextInt -> 73
    $poll$3$invokeSuspend$$inlined$collect: Debug: collect 2 -> 73
    $poll$2$invokeSuspend$$inlined$collect: Debug: collect 1 -> 59
    $poll$4$invokeSuspend$$inlined$collect: Debug: collect 3 -> 68
    s
    d
    • 3
    • 14
  • a

    andylamax

    07/16/2021, 4:06 PM
    I wanna take this time to appreciate IntelliJ devs. Combining the in-editor html viewer and TDD, this is what one gets. I am so loving this
    👏🏼 4
    👏 4
    :not-kotlin: 4
    c
    • 2
    • 1
  • c

    Chetan Tuteja

    07/17/2021, 11:48 AM
    Can anyone tell me how is Kotlin interoperable with Java? Like I know it is, but how does that work?
    d
    z
    +2
    • 5
    • 10
  • l

    Lefko

    07/18/2021, 9:32 AM
    Anyone familiar with a library which takes json schema and generates kotlin classes?
    m
    p
    c
    • 4
    • 10
  • j

    Jason Roberts

    07/19/2021, 5:13 AM
    I need an android modular(feature base) source sample with jetpack compose, can anybody introduce to me?
    a
    • 2
    • 3
  • a

    Amit Kumar Kar

    07/19/2021, 8:17 AM
    Hello, I am trying to build a desktop(JVM) app using kotlin and works fine on Ubuntu but when tried build on MAC after creating a package and installing it there is no window appear. Does anybody face this issue and if fixed it then please help me out.
    👀 1
    d
    • 2
    • 2
  • u

    user

    07/19/2021, 2:09 PM
    message has been deleted
    e
    • 1
    • 1
  • m

    Mohammad Jahidul Islam

    07/19/2021, 2:58 PM
    Capitalize is deprecated in Kotlin 🙄
    c
    z
    +2
    • 5
    • 4
  • n

    Nick

    07/19/2021, 3:20 PM
    What is preferred:
    lateinit var
    or assigning the value to a
    val
    that way it’s not mutable? Example lateinit var:
    late init var foo: Bar()
    
    fun goTime() {
       foo = Bar()
       println(foo)
    }
    Example var:
    var foo: Bar? = null
    
    fun goTime() {
       val foo = foo ?: Bar()
       println(foo)
    }
    s
    e
    • 3
    • 5
  • i

    Ifvwm

    07/20/2021, 10:29 AM
    except Intelij IDEA, is there other IDE can run kotlin code?
    b
    c
    g
    • 4
    • 3
  • i

    Ifvwm

    07/20/2021, 10:35 AM
    fun parseIntEither(s: String): Either<NumberFormatException, Int> =
            if (s.matches(Regex("-?[0-9]+"))) Either.Right(s.toInt())
            else Either.Left(NumberFormatException("$s is not a valid integer."))
    
        val list = listOf("1", "2", "3").k().traverse(Either.applicative(), ::parseIntEither)
        val failFastList = listOf("1", "abc", "3", "4s").k().traverse(Either.applicative(), ::parseIntEither)
    
    red line under Either.applicative(), 
    Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6
    I can't find a solution on IDEA, but it's ok on Android Studio, and IDEA using the same JDK 1.8 from Android Studio
    c
    • 2
    • 4
  • r

    Raed Ghazal

    07/20/2021, 1:24 PM
    hey guys, is there a way to create a
    const
    list/array inside a companion object in kotlin?
    🇳🇴 1
    i
    • 2
    • 2
  • l

    Ludovik

    07/20/2021, 2:21 PM
    Any known issue with that endpoint atm ? https://kotlin.bintray.com/kotlinx/org/jetbrains/kotlinx/kotlinx-coroutines-core-jvm/1.5.1/kotlinx-coroutines-core-jvm-1.5.1.jar -> forbidden it looks like resolution dependency has issues since yesterday 2/3pm .. pls any help is welcome
    r
    • 2
    • 2
  • a

    Ayfri

    07/20/2021, 4:52 PM
    https://github.blog/changelog/2021-07-19-machine-translation-for-discussions-content/ cool !
    🔝 1
    m
    • 2
    • 1
  • a

    allan.conda

    07/20/2021, 10:15 PM
    I’m looking for ideas on designing an interface in Kotlin. 🙏 I’d like to keep the data type as simple as a String. I want different classes to take that String, and I want to write extension convenience functions for that particular type of String. I think I have to Box the string, but wondering if there’s a nice Kotlin to seamlessly unbox the Strings. Sample code in thread
    h
    p
    • 3
    • 7
  • j

    Jérémy CROS

    07/21/2021, 12:30 PM
    Noticed something while writing some unit tests:
    class Foo
    
    class Bar(
        private val foo: Foo
    ) {
    
        override fun equals(other: Any?): Boolean {
            if(other !is Bar) return false
            return this.foo == other.foo // it works?
        }
    
        override fun hashCode(): Int {
            return foo.hashCode()
        }
    }
    
    fun test() {
        val foo = Foo()
        val bar = Bar(foo)
        val test = bar.foo // private, cannot access
    }
    Could not find any documentation on this behavior. I mean, seemed convenient but it just felt... weird that it worked on the equals override 🙂
    c
    m
    l
    • 4
    • 7
  • e

    eygraber

    07/22/2021, 5:16 AM
    Is there a known issue with inline classes that have a type
    T
    where an inlined property that uses a
    with
    scope on an instance of the same type as
    T
    gets unwrapped to use the class instance instead of the actual one? Something like (using custom extensions on
    JsonObject
    ):
    @JvmInline
    value class MyJson(val json: JsonObject) {
      inline val type
        get() = with(json.jsonObject("type") {
            string("actual_type") // this crashes at runtime because it is looking for this field in the json property instead of the one from the with scope
        }
    }
    Switching to `json.jsonObject("type").let { type ->`works
    a
    • 2
    • 3
  • s

    Stephan Schroeder

    07/22/2021, 7:15 AM
    We have several old Java projects using Lombok that we'd like to convert to Kotlin. We used the @Builder-annotation extensively and it's not yet supported by Kotlin. Unfortunately converting this code manually turned out to be too much of a hassle. If you're in a similar situation, maybe vote up the youtrack ticket: https://youtrack.jetbrains.com/issue/KT-46959?_gl=1*q24pg*_ga*NDY2MzY3ODA3LjE2MjY2NzUwND[…]_ga=2.20803896.1078897134.1626675045-466367807.1626675045
    t
    e
    • 3
    • 5
  • n

    nfrankel

    07/22/2021, 2:27 PM
    and the other 3 run spring boot 😅
    :trollface: 7
    c
    j
    p
    • 4
    • 10
  • p

    Phillip Schichtel

    07/22/2021, 8:32 PM
    Hi everyone! I've recently built a small socket.io client library using ktor (https://github.com/pschichtel/Kognigy). I'm currently trying to deploy it to maven central. I've setup tasks for the sources jar and javadocs jar (based on dokka). when I publish using the
    io.github.gradle-nexus.publish-plugin
    plugin and
    from(components["java"])
    in the publication, then everything gets uploaded except the actual code jar: https://oss.sonatype.org/#nexus-search;quick~kognigy. This happens both with gradle 6.8 and 7.1. Am I missing something?
    t
    • 2
    • 2
  • j

    jimn

    07/22/2021, 9:11 PM
    hi, i have wasted an embarrassing amount of time trying to fit
    fold
    , or
    reduce
    to this, finally, i just did it as a while loop. is there a one-liner for this ?
    var acc = sim.outputRange.indices
            val tree = sortedSetOf<Int>()
            while (acc.isNotEmpty()) {
                tree += acc;
                  acc = acc.map { this.usefulScope(it) }.flatten().filter {
                    it in sim.hiddenRange } - tree
            }
    e
    p
    r
    • 4
    • 13
  • a

    Austin Paquette

    07/22/2021, 9:38 PM
    Hey all, question about reflection, I am trying to do something like this but I am inexperienced with Kotlin and even brand new to reflection.
    class Example(val id: Int) {
        companion object {
            fun <T, V> demo(property: KProperty1<T, V>, value: V): V? {
                return null
            }
        }
    }
    
    // this works
    val test1 = Example.demo(Example::id, 0)
    
    // this works, but shouldn't pass validation
    val test2 = Example.demo(Example::id, "1")
    The idea is that I want to be able to infer the type of the passed-in property (in this case I would expect
    Int
    . I feel like I'm close but not understanding something. Any help (or even suggestions of what to Google) would be awesome.
    l
    s
    y
    • 4
    • 18
  • u

    user

    07/23/2021, 7:58 AM
    message has been deleted
    e
    • 1
    • 1
  • d

    David Smith

    07/23/2021, 3:24 PM
    has anyone ever managed to include a git source repo in a gradle project?
    m
    p
    • 3
    • 5
  • d

    David Smith

    07/23/2021, 4:12 PM
    has anyone managed to get a gradle kotlin multplatform project working correctly in intellij? For some reason intellij only sees the jvmMain and jvmTest source sets as source and commonMain etc don’t seem to work very well, for example intellij can’t see the dependencies that I have added to the commonMain source set
    k
    a
    • 3
    • 3
Powered by Linen
Title
d

David Smith

07/23/2021, 4:12 PM
has anyone managed to get a gradle kotlin multplatform project working correctly in intellij? For some reason intellij only sees the jvmMain and jvmTest source sets as source and commonMain etc don’t seem to work very well, for example intellij can’t see the dependencies that I have added to the commonMain source set
k

kevindmoore

07/23/2021, 4:26 PM
I'm using Android Studio but having the same problem. If I have a Kotlin section without a jvm target I get an error
a

andylamax

07/25/2021, 10:42 AM
I remember it being a problem for Android studio, but not for IntelliJ. However, recent versions of AS also work flawlessly with KMP
Just check to see if your gradle syncs correctly. IDEA goes berserk when gradle sync fails
View count: 6