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
getting-started
  • k

    Klitos Kyriacou

    10/04/2022, 2:02 PM
    Why does Kotlin allow the following?
    try {
            foo()
        } catch (e: Exception) {
            //...
        } catch (e: RuntimeException) {
            //...
        }
    The Java compiler rejects it because it knows that RuntimeException will never be caught as it appears after Exception. The Kotlin equivalent doesn't even trigger a warning in the IDE. Does the Kotlin plugin for IntelliJ IDEA have at least an option to turn on a warning for this?
    e
    • 2
    • 2
  • c

    Curtis Ullerich

    10/04/2022, 5:20 PM
    I'm experimenting with writing a tree matching DSL in Kotlin. Anybody know if there's something similar out there already?
    m
    g
    • 3
    • 4
  • r

    Ruckus

    10/05/2022, 2:06 PM
    Why are reified types forbidden for catch parameters?
    j
    • 2
    • 2
  • g

    Greg

    10/05/2022, 6:01 PM
    There was a page on Kotlin docs site that listed recommended version of libraries (like coroutines, ktor, etc.) for every kotlin version but I cannot find it now?
    e
    • 2
    • 1
  • d

    Daniel Zayas

    10/05/2022, 7:00 PM
    JetBrains' Kotlin learning materials & Effective Java & Atomic Kotlin 🧵
    g
    k
    m
    • 4
    • 6
  • j

    Jose Garcia

    10/06/2022, 11:28 AM
    Hey guys, we are migrating from Ktor 1.6.x to 2.x.x and we found that in the previous version of the lib any unsuccessful http response (e.g. 404 error) would throw a
    ClientRequestException
    . However in 2.x, it seems that unsuccessful http responses are not throwing exceptions anymore. This is forcing us to check which status code we get on the response and throw our own custom NetworkError. I am wondering if there is anyone here that can have information on why is this done like that, we are thinking that may have something to do with the newly added retry functionality.
    r
    • 2
    • 2
  • g

    Giorgi

    10/06/2022, 12:26 PM
    👋 Hello, team!
  • s

    Stylianos Gakis

    10/06/2022, 11:28 PM
    I was reading the article "EventListener is Like Logging, But Good", and I was particularly interested in the section that reads: “Create an abstract class
    EventListener
    . I prefer an abstract class over an interface here ’cause I want to introduce new functions in library upgrades without breaking compatibility.” I always thought even if you’ve got an interface, you can introduce new functions with default implementations which would let consumers not need to do anything in implementation of that interface. Am I missing something here?
    c
    • 2
    • 5
  • o

    oday

    10/07/2022, 9:55 AM
    is there an
    import as
    in kotlin? I need to use two classes that are called the same but different packages and I dont want my entire package name behind each usage of one or the other to differentiate
    s
    v
    b
    • 4
    • 5
  • j

    Jasmin Fajkic

    10/07/2022, 10:07 AM
    How to combine for example flows?
    private fun <T1, T2, T3, T4, T5, T6, T7, R> combine(
        flow: Flow<T1>,
        flow2: Flow<T2>,
        flow3: Flow<T3>,
        flow4: Flow<T4>,
        flow5: Flow<T5>,
        flow6: Flow<T6>,
        flow7: Flow<T7>,
        transform: suspend (T1, T2, T3, T4, T5, T6, T7) -> R
    ): Flow<R> = combine(
        combine(flow, flow2, flow3, ::Triple),
        combine(flow4, flow5, flow6, ::Triple),
        combine(flow7)
    ) { t1, t2, t3 ->
        transform(
            t1.first,
            t1.second,
            t1.third,
            t2.first,
            t2.second,
            t2.third,
            t3.first,
        )
    }
    e
    • 2
    • 3
  • z

    zt

    10/08/2022, 11:35 PM
    I want to create a type of history thing in my project, where the users actions are added to a list or some other array, and then the user can go back or forward. It should behave like how you can go back and forth in a file browser. I'm unsure how to represent this in code though. Any ideas?
    c
    m
    • 3
    • 4
  • j

    janvladimirmostert

    10/09/2022, 4:51 PM
    object A {
        fun Server.wire() { TODO() }
    }
    
    object B {
        fun Server.wire() { TODO() }
    }
    how do I call wire from both object A and B considering they're both extension functions?
    Server().apply {
        wire() // wire A
        wire() // wire B
    }
    is it possible to do something like
    A::wire()
    and
    B::wire()
    ?
    e
    j
    • 3
    • 6
  • e

    ephemient

    10/10/2022, 6:44 PM
    https://youtrack.jetbrains.com/issue/KT-17172/LongMINVALUE-literal-can-not-be-compiled
    g
    • 2
    • 3
  • g

    Gavin Ray

    10/10/2022, 7:55 PM
    I have some basic questions about working with Coroutines and JVM
    CompleteableFuture
    interop I'm not very familiar with JVM-style asynchrony (mostly used async/await style languages) If I have a Java API which returns `CompleteableFuture`'s, is there a way to get them to run on coroutines instead of physical threads to reduce the overhead, or how do you generally work with these?
    a
    g
    • 3
    • 6
  • g

    Gavin Ray

    10/10/2022, 7:56 PM
    (Maybe my thinking/approach here is entirely wrong, too)
  • r

    Rob Elliot

    10/11/2022, 7:19 AM
    Am I right that implementing interfaces by delegation is restricted to constructor fields? I'd quite like to delegate to a method that returns an instance of the interface, as I can in Groovy.
    e
    • 2
    • 4
  • y

    y

    10/11/2022, 11:43 AM
    how do I declare a static val in Kotlin?
    v
    l
    +2
    • 5
    • 12
  • o

    Oleg Shuliak

    10/11/2022, 2:27 PM
    good day everyone. got a coroutine question. I want to set the property value for each object in the list by calling the suspension function and setting the result:
    coroutineScope {
                workflows.forEach {
                    it.status = formWorkflowActivationStateManager.getCurrentState(it, companyId).toWorkflowStatus()
                }
            }
    I’m wondering if the
    coroutineScope
    is enough to parallel those executions or if I need to use
    async/await
    ?
    s
    s
    y
    • 4
    • 9
  • r

    Roque Sosa

    10/11/2022, 6:25 PM
    Hi All, what would you recommend to learn Kotlin for someone who's been coding in Java with Spring for 5 years. I started the Kotlin Koans, Atomic Kotlin, and Kotlin courses in JetBrains Academy but none of those seems right to me. Is there any other option?
    c
    m
    +3
    • 6
    • 6
  • y

    y

    10/12/2022, 6:54 AM
    is it idiomatic to avoid the use of
    this
    when possible?
    s
    m
    +2
    • 5
    • 5
  • s

    sarvagya agarwal

    10/12/2022, 11:10 AM
    what's the best practice to implement transactions when dealing with coroutines ? Essentially I am launching some parallel tasks and want to rollback everything in case one fails
    e
    j
    b
    • 4
    • 4
  • m

    Moritz Post

    10/12/2022, 1:50 PM
    Hello. Is there something more elegant than the following to invoke each lambda in a list?
    lambdas.forEach { it() }
    m
    m
    +2
    • 5
    • 11
  • e

    Erfannj En

    10/12/2022, 2:05 PM
    Hello friends, I had a question about making a mobile application. For the basic structure of the application, which is just an idea and you want to turn it into an application, what steps should I go through? I mean, what questions should I ask myself about the idea and that How should I create a road map according to which I will start building the app so that I don't get interrupted when turning the idea into an app and don't change my decision for a sudden part? I don't mean the programming stage
    r
    i
    • 3
    • 2
  • a

    Abdullah Samir

    10/12/2022, 8:17 PM
    Hello u work now with java and kotlin and want to know that when i run java app where is the code in memory or instruction set in jvm, My question where is my code in JVM?
    g
    • 2
    • 3
  • j

    Justin Xu

    10/13/2022, 1:19 AM
    Hi all, I am trying to make a
    User
    model object to be inserted into a database. I want to insert these into various databases using a Repository pattern, but the
    User
    has an
    id
    field that is generated differently for each database I use. Is there a way to defer the definition of the
    id
    type and a
    generateId()
    function until the actual creation of the
    User
    object in Kotlin? Thanks
    g
    c
    m
    • 4
    • 5
  • b

    Blitzer

    10/13/2022, 3:30 AM
    Hi all, I wanted to know what is the meaning of the statement "If the class has a primary constructor, each secondary constructor needs to delegate to the primary constructor, either directly or indirectly through another secondary constructor(s)." in simple English.
    k
    r
    a
    • 4
    • 10
  • o

    oday

    10/13/2022, 3:42 PM
    why is it that when I have a
    when
    like this one
    when (locationState) {
        !is LocationState.Set -> {}
        is LocationState.Disabled -> onLocationDisabled()
        is LocationState.NotGranted -> onLocationNotGranted()
        else -> Unit
    }
    all the conditions after the first
    !is LocationState.Set
    are now unreachable?
    a
    • 2
    • 10
  • m

    martmists

    10/13/2022, 4:20 PM
    IntelliJ resolves the functions just fine, so why is gradle giving this error?
    e
    l
    • 3
    • 3
  • l

    Loney Chou

    10/14/2022, 3:17 AM
    I wonder why
    class
    only implies
    final
    but
    override
    only implies
    open
    ? Should "overridability" be `open`'s at all? I remember this is the only place where
    final
    is used.
    class A // final
    
    interface B {
        fun foo()
    }
    
    class C : B {
        override fun foo() // final
    }
    
    open class D : B {
        override fun foo() // OPEN
    }
    if it's final by default then
    D.foo
    should also just finalize overridability UNLESS you mark it
    open
    . Having both
    open
    and
    final
    is so inconsistent.
  • e

    Ellen Spertus

    10/15/2022, 4:15 AM
    I understand why the first statement prints
    true
    but not why the second one does. I'd only expect substrings of the alphabet to return
    true
    . What's going on?
    Untitled.cpp
    k
    v
    v
    • 4
    • 6
Powered by Linen
Title
e

Ellen Spertus

10/15/2022, 4:15 AM
I understand why the first statement prints
true
but not why the second one does. I'd only expect substrings of the alphabet to return
true
. What's going on?
Untitled.cpp
k

Kevin Healy

10/15/2022, 4:30 AM
It's checking whether the string would fall in the range using the default string comparator, which is alphabetical order. "apple" would indeed be after "a" and before "z" alphabetically
More in-depth answer here https://stackoverflow.com/a/46764287
e

Ellen Spertus

10/15/2022, 4:36 AM
Very cool! I verified that the following expression is false:
"zz" in "a".."z"
v

vimlesh yadav

10/15/2022, 10:02 AM
apple doesn't fall in the range a..z
v

Vampire

10/15/2022, 10:35 AM
Why not? Obviously it does.
e

Ellen Spertus

10/15/2022, 4:12 PM
According to
compareTo()
it does.
View count: 4