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

    Sam

    07/23/2021, 5:05 PM
    Hello! Can anyone tell me if there's a neater way of doing this? I'm trying to essentially run some code after a specified delay, but I want to handle the case the function is called before it's actually finished executing.
    private var job: Job? = null
        private fun scheduleJob() {
            job?.cancel()
            job = flow<Void> {
                delay(mySpecifiDelay)
                doWork()
            }.launchIn(CoroutineScope(coroutineDispatcher))
        }
    d
    a
    • 3
    • 7
  • k

    Kareem Radwan

    07/23/2021, 8:02 PM
    hi all, there any channel for Testing ( Unit Test ) ?
    👍 1
    b
    l
    • 3
    • 4
  • a

    Alexey Yakovlev

    07/24/2021, 10:36 AM
    Hi all, Why Kotlin Any type has only 3 methods equals, hashCode and toString. While standard Java Object type has some additional ones like wait/notify
    n
    • 2
    • 2
  • p

    Piotr Krzemiński

    07/24/2021, 12:09 PM
    I'm planning to prepare a presentation for a KUG meeting on this topic: "_10 surprises when coming from Java to Kotlin_". Please share in this thread things that in your opinion would be worth mentioning in the presentation :) I have my thoughts, but reaching to the community because maybe I forgot about something important (started with Kotlin 4 years ago, might have forgotten something).
    👍 2
    b
    c
    +3
    • 6
    • 16
  • d

    Danish Ansari

    07/24/2021, 3:33 PM
    Can someone please help me with this? https://stackoverflow.com/questions/68511430/jackson-serialisation-fails-by-throwing-kotlinreflectioninternalerror-when-seria
    j
    • 2
    • 47
  • j

    Jgafner

    07/25/2021, 8:04 AM
    Hi I am having a map like this: [ key1 : [1,2,3], key2: [2,3,4], key3: [3,4,5]] I would like to get a map like this: [1:[key1],2:[key1,key2],3:[key1,key2,key3],4:[key2,key3],5:[key3]] any suggestions on how to group by elements in a list and not the list itself? Thanks
    l
    p
    • 3
    • 8
  • l

    li'lfluf

    07/25/2021, 12:37 PM
    how do i insert an unicode character literal, value of which is more than
    0xffff
    ?
    \U12345678
    doesn't seem to work
    d
    • 2
    • 3
  • d

    Dirk Seewald

    07/25/2021, 9:21 PM
    Is there a way i can fix that?
    l
    • 2
    • 10
  • s

    spierce7

    07/26/2021, 3:55 AM
    Is there a way to force when statements to be exhaustive officially yet? I remember it was talked about. Right now I’m just putting a
    .let {}
    at the end of my when statements.
    a
    c
    +2
    • 5
    • 6
  • j

    Jason Roberts

    07/27/2021, 5:14 AM
    Hi, Do jetpack compose trustworthy for business applications? And can we publish an application written with Jetpack compose on Google Play?
    :yes: 3
    c
    • 2
    • 1
  • i

    iamthevoid

    07/27/2021, 6:44 AM
    Is it possible in Kotlin get function argument from function instance? For example i want kind of
    retry
    function
    fun <T, R> ((T, R) -> Unit).retry() {
            this(argument1, argument2)
        }
    My real case a bit more complicated, here just extraction for clear my question.
    l
    j
    +2
    • 5
    • 20
  • z

    Zahara Vidumshikova

    07/27/2021, 7:03 AM
    Hi, how can i make an universal comporator in kotlin?
    fun<T : Comparable<T>, K> comparePairByFirst() : Comparator<Pair<T, K>>  = Comparator { p1, p2 -> p1.first.compareTo(p2.first) }
    I have this code and it works, but creates a new similar comparator every use. I think it is bad. How can I make it better? ------------------------------------------------------------------------------------------------------------------------------------------------------------ How i can "this" method in inline functions? I want to get that class to log it.
    e
    • 2
    • 4
  • z

    Zahara Vidumshikova

    07/27/2021, 3:34 PM
    Kotlin inline functions create a lot of copies of java-primitive types. Parameters in kotlin are final so java-primitive elements can not be changed. How can I fix it? Maybe by annotations or compiler flags?
    y
    • 2
    • 1
  • m

    Michal Klimczak

    07/27/2021, 4:04 PM
    Is it possible to count graphemes instead of characters in pure kotlin (one that works in both jvm and native)? I'm looking for something like this but for pure kotlin: https://stackoverflow.com/a/29743275/1118475. E.g. an emoji in utf16 will be counted as two characters with 
    emojiText.length
     and I would like a method which returns 
    1
    .
    e
    c
    • 3
    • 8
  • t

    Tomasz Krakowiak

    07/27/2021, 4:46 PM
    Any idea, how to troubleshoot:
    Error: Could not find or load main class org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
    Caused by: java.lang.ClassNotFoundException: org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
    1.5.21 gradle plugin, tried different SDKs, upgrading plugin to 1.5.30-M1, downgrading to 1.5.20, 1.5.10. Cleaning project, removing whole $HOME/.gradle directory. This error relates to submodule of multi-project project. Modules use either jvm or mpp plugin.
    • 1
    • 1
  • g

    Gopal S Akshintala

    07/28/2021, 4:23 AM
    Java Interoperability question: Can’t we access Inline Value class fields and constructor from Java? In the below example I don’t get any compiler error but fails at runtime with
    error: cannot find symbol
    # Kotlin Value class
    import io.vavr.control.Either
    import io.vavr.kotlin.right
    
    @JvmInline
    value class Name(val s: String) {
        val length: Int
            get() = s.length
    }
    
    fun getAsName(): Either<String, Name> = right(Name("Kotlin"))
    # Java Client
    @Test
    void testValueClass() {
      final var name = getAsName().get();
      Assertions.assertEquals(0, name.getLength());
    }
    # Error
    error: cannot find symbol
        Assertions.assertEquals(0, name.getLength());
                                       ^
      symbol:   method getLength()
      location: variable name of type Name
    r
    g
    • 3
    • 10
  • a

    althaf

    07/28/2021, 6:08 AM
    hi i'm trying to reduce the visibility of an extension written to fragment. So this extension should be only visible at package level.
    package com.abcd.registration
    internal fun 
    
    Fragment.showUserAlreadyRegisteredOnAnotherDevice(actionProceedToRegister: (() -> Unit)?,
                                                                   actionCancel: (() -> Unit)?) {
        activity?.supportFragmentManager?.let {
            var alreadyRegisterAnotherDeviceBottomSheet: AlreadyRegisterAnotherDeviceBottomSheet =
                    AlreadyRegisterAnotherDeviceBottomSheet.getInstance(
                            actionProceedToRegister,
                            actionCancel)
    
            alreadyRegisterAnotherDeviceBottomSheet?.show(it, "BottomSheet")
        }
    }
    I want this to be visible to only registration package any top level package should be able to use this extension even if they are inheriting from Fragment. Is this doable. I added internal keyword, still it is not working here. Any inputs ?
    r
    t
    • 3
    • 3
  • h

    Himani Vohra

    07/28/2021, 6:59 AM
    I have done the installation as per the instructions
    n
    • 2
    • 10
  • m

    maarten ha

    07/28/2021, 9:39 AM
    Currently I’m trying to automate een excel task for my work in python but want to convert it to kotlin. I am using XLwings lib because this was the only lib that supports the xlsb format. Is there a way to automate it directly in kotlin or run the python script? the automations exist of opening a template, inserting data in 1 sheet, running a macro on another sheet and saving it with a custom name.
    v
    p
    • 3
    • 5
  • d

    Danish Ansari

    07/28/2021, 12:54 PM
    I simply want to ask why
    toUpperCase()
    and
    toLowerCase()
    got deprecated in
    1.5
    uppercase()
    and
    lowercase()
    seems to have exactly same code, so why rename such a common method name after such stability of the language?
    b
    • 2
    • 3
  • m

    Michael Nitschinger

    07/28/2021, 4:06 PM
    Hi everyone - I briefly wanted to mention that we released our first developer preview of the Couchbase Kotlin SDK: https://forums.couchbase.com/t/ann-couchbase-kotlin-sdk-1-0-0-dp-1/31223 - we’d love to get feedback! I created a #couchbase channel for it.
    👍 2
    🎉 2
    l
    a
    n
    • 4
    • 8
  • j

    Jilles Soeters

    07/28/2021, 8:08 PM
    Are there currently any book recommendations? The docs are fantastic but I like diving into a book with some actual project examples 🙂
    c
    k
    +3
    • 6
    • 14
  • s

    spierce7

    07/29/2021, 2:53 AM
    I just took the Kotlin badge test on LinkedIn. It doesn’t tell me the answers so I don’t know for sure. There are a LOT of small wording problems in the quiz where it’s not clear if they are trying to gotcha you or not. i.e. They show you a function and call it
    shouldEqual
    , but the correct answer calls the function
    shouldMatch
    . There were lots of small little mistakes in the correct answers that make you question whether or not it’s the correct answer.
    :kotlin: 2
    e
    • 2
    • 11
  • j

    juliocbcotta

    07/29/2021, 2:03 PM
    So, I have these extension functions
    @file:JvmName("UriDeepLinkFactory")
    ...
    fun UriDeepLink.Companion.from(uri: Uri): UriDeepLink {
        return UriDeepLink(UriParameter(uri)) { scheme -> Schemes.valueOf(scheme) }
    }
    fun UriDeepLink.Companion.from(uriString: String): UriDeepLink {
        return UriDeepLink.from(Uri.parse(uriString))
    }
    But when I try to access it from java I get the error at compile time
    final UriDeepLink deepLink = UriDeepLinkFactory.from(operationDeepLink);
                                                           ^
        method UriDeepLinkFactory.from(Companion,Uri) is not applicable
          (actual and formal argument lists differ in length)
        method UriDeepLinkFactory.from(Companion,String) is not applicable
          (actual and formal argument lists differ in length)
    Any idea of how to fix it ?
    r
    • 2
    • 1
  • j

    Jérémy CROS

    07/29/2021, 2:05 PM
    I assume there is a bug somewhere between AS or the kotlin compiler? anything I can do besides having the warning for the time being?
    e
    j
    • 3
    • 5
  • k

    Karlo Lozovina

    07/29/2021, 7:07 PM
    Why doesn't this compile, it feels like it should?
    abstract class A {
        open val x: String? = null
    }
    
    sealed class B : A() {
        override val x = "x"
    }
    
    class C : B() {
        override val x = null
    }
    If I add a type annotation on
    B.x
    of
    String?
    , then it works...
    r
    s
    y
    • 4
    • 15
  • t

    Travis Griggs

    07/29/2021, 9:26 PM
    Like Kotlin, Swift supports implicit self/this. I ran a poll over in the Swift forums to see who embraced implicit, and who embraced explicit. I honestly expected implicit to be +95%. I was surprised that the breakdown was 29% explict, 71% implicit, out of 140 votes. I'm curious what the breakdown is in the Kotlin crowd. Poll: Implicit this = 🔵 (
    :large_blue_circle:
    ), Explicit this = :large_green_square: (
    :large_green_square:
    )
    🔵 40
    :large_green_square: 1
    a
    b
    +3
    • 6
    • 5
  • k

    Kefas

    07/30/2021, 5:17 AM
    Hi, why are the results different?
    fun main() {
        val a: () -> Unit = { }
        val b: () -> Unit = { }
        val c = generateLambda()
        val d = generateLambda()
    
        println(a == b) // false
        println(c == d) // true
    }
    
    fun generateLambda(): () -> Unit {
        return { }
    }
    z
    s
    y
    • 4
    • 7
  • m

    MrNiamh

    07/30/2021, 8:46 AM
    Struggling to understand why the overriding works with val but not with var. What changes with var? This works:
    class A (
        override val values: List<A>
    ) : B
    
    interface B {
        val values: List<B>
    }
    This does not:
    class A (
        override var values: List<A>
    ) : B
    
    interface B {
        var values: List<B>
    }
    l
    j
    r
    • 4
    • 4
  • j

    Jomon G

    07/30/2021, 8:51 AM
    👋 Just joined. Im a beginner in Kotlin. Hope to explore more 🙂
    :kotlin-intensifies: 5
    👋 23
    👋🏻 1
    :parrot-upside-down: 4
    • 1
    • 1
Powered by Linen
Title
j

Jomon G

07/30/2021, 8:51 AM
👋 Just joined. Im a beginner in Kotlin. Hope to explore more 🙂
:kotlin-intensifies: 5
👋 23
👋🏻 1
:parrot-upside-down: 4
Thank you all for your support 😊
View count: 10