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

    Animesh Sahu

    11/14/2020, 5:05 AM
    What is general requirement of PC to open a large project (like Kotlin itself) in Intellij? Seems the intellij is eating so much RAM ~2.8GB but still not able to index anything (only getting purple-white highlighted).
    r
    c
    +2
    • 5
    • 9
  • e

    Edoardo Luppi

    11/14/2020, 5:29 PM
    Is there a more Kotlin-like alternative to express this piece of code?
    var n = completionProviders.indexOfFirst(...) + 1
    
    if (n == 0) {
      n = completionProviders.size
    }
    Not with takeUnless/takeIf
    r
    n
    e
    • 4
    • 16
  • n

    Nikky

    11/15/2020, 11:40 AM
    would be cool to have nullsafe operator variants.. especially for
    get
    .. would avoid some ugly hacks with
    let
    or assigning intermediary variables not sure if that would promote writing worse code and longer nullsafe call chains..
    e
    a
    • 3
    • 4
  • c

    ciscorucinski

    11/15/2020, 2:12 PM
    I was going through an older Kotlin tutorial, and noticed some nice upgrades to the language. However, there is one place that seems so strange. This deals with varargs, arrays, spread operator, and named parameters.
    fun sayHello(greeting: String, vararg names: String) {
        names.forEach { name ->
            println("$greeting $name")
        }
    }
    
    fun main() {
        val interestingThings3 = arrayOf("Kotlin", "Programming", "Coding")
        sayHello(greeting = "Hi", *interestingThings3)
        sayHello(greeting = "Hi", names = *interestingThings3)
    }
    This works, but the last statement suggests to remove
    Redundant spread (*) operator
    . That leads to the following valid code.
    fun main() {
        val interestingThings3 = arrayOf("Kotlin", "Programming", "Coding")
        sayHello(greeting = "Hi", *interestingThings3)
        sayHello(greeting = "Hi", names = interestingThings3)
    }
    Since the last statement doesn't need the spread operator, I thought I would remove it from both
    fun main() {
        val interestingThings3 = arrayOf("Kotlin", "Programming", "Coding")
        sayHello(greeting = "Hi", interestingThings3)  // ERROR
        sayHello(greeting = "Hi", names = interestingThings3)
    }
    But this gives an error on the first statement. Why? Why does the first one error out, but the last one if perfectly fine.
    n
    k
    k
    • 4
    • 8
  • w

    william

    11/15/2020, 5:28 PM
    i'm trying to write a binary tree in kotlin with
    sealed class BinaryTree<T> {
        val root: BinaryTree<T> = Leaf
    }
    
    data class Node<T>(val data: T, val left: BinaryTree<T>, val right: BinaryTree<T>) : BinaryTree<T>()
    object Leaf : BinaryTree<Nothing>()
    can anyone help my understand why
    root: BinaryTree<T> = Leaf
    gives the error
    Type mismatch.
    Required:
    BinaryTree<T>
    Found:
    Leaf
    e
    n
    • 3
    • 20
  • f

    Florian

    11/15/2020, 7:05 PM
    val searchQuery = state.getLiveData("query", "")
    
    private val tasksFlow = combine(
            searchQuery.asFlow(),
            preferencesFlow
        ) { query: String, filterPreferences: FilterPreferences ->
            Pair(query, filterPreferences)
        }.flatMapLatest { (query, filterPreferences) ->
            taskDao.getTasks(query, filterPreferences.sortOrder, filterPreferences.hideCompleted)
        }
    If I set
    searchQuery.value = null
    this will crash. How can I get null-safety here?
    a
    • 2
    • 6
  • z

    zero_coding

    11/15/2020, 9:00 PM
    https://stackoverflow.com/questions/64848668/how-to-output-that-the-server-has-been-started
    n
    • 2
    • 1
  • n

    Nuru

    11/16/2020, 9:46 AM
    Have gone through the official docs and some tutorials online but still quite unsure where and when to use Interface Delegation. When do you use Interface Delegation in your projects? 🤔 Examples and instances would be greatly appreciated. 🙏🏾
    n
    r
    u
    • 4
    • 3
  • a

    Animesh Sahu

    11/16/2020, 10:26 AM
    Any plans for suspendable property getters?
    👎 3
    👍 1
    ➕ 1
    e
    • 2
    • 1
  • e

    Edoardo Luppi

    11/16/2020, 2:33 PM
    Does anyone see the same issue? I can't import extension functions from the Locks file. I'm on 1.4.20-RC Obviously that also breaks file parsing, which runs forever.
    l
    • 2
    • 2
  • u

    user

    11/16/2020, 3:03 PM
    message has been deleted
    p
    • 1
    • 1
  • i

    Iaroslav Postovalov

    11/16/2020, 3:35 PM
    Is it even possible to create a method reference to such a function?
    public operator fun T.minus(b: T): T = add(this, -b)
    ✅ 1
    d
    r
    • 3
    • 2
  • r

    ribesg

    11/16/2020, 3:56 PM
    How do you name whatever can be called on a class? Like properties + methods + extensions. Basically what’s the word for “members + extensions of class X”?
    l
    n
    +3
    • 6
    • 11
  • t

    thana

    11/16/2020, 7:13 PM
    Hi, having upgraded to 1.4 i get an
    OutOfMemoryException
    during
    compileKotlinJs
    . Any idea how to tackle that?
    c
    g
    • 3
    • 6
  • a

    Alberto

    11/17/2020, 4:29 AM
    Hi, what is the convention when having a suspend and non-suspend version of the same method, which one contains the actual implementation? For example, when having a
    get()
    method (non-suspend) and a
    getAsync()
    method (suspendable), which one should own the logic/implementation? Option 1 (suspendable owns the logic/implementation):
    fun get(): String {
      return runBlocking {
        getAsync()
      }
    }
    
    suspend fun getAsync(): String {
    	  // actual getter logic
    }
    Option 2 (non-suspendable owns the logic/implementation):
    fun get(): String {
      // actual getter logic
    }
    
    suspend fun getAsync(): String {
      	withContext(dispatchers.default()) {
    		return get()
    	}
    }
    e
    a
    a
    • 4
    • 7
  • h

    hhariri

    11/17/2020, 8:15 AM
    IMPORTANT Folks, please remember that the purpose of this Slack is for Kotlin and anything related to Kotlin. It is not a general platform to have channels and discussions around technology in general. As such, creating channels that are off-topic (i.e. a channel on MVVM architecture for instance….just made that up, not sure if it exists), is not really acceptable. Why this policy? Because this is about Kotlin and the Kotlin community. If we start allowing a variety of off-topic channels, tomorrow we may very-well end up with many different channels that are no longer remotely related to Kotlin, and then it no longer becomes a Kotlin Community but a strange form of StackOverflow as a Slack instance. We realise it’s often hard to distinguish between a general topic and its relation to Kotlin, but, a good rule of thumb is to find the intersection between the two. If there is intersection, then it makes sense to discuss/have channels around the topic. Appreciate your understanding on this matter. Thanks.
    👏 11
    💯 14
    ⭐ 3
    :kotlin-intensifies: 11
    👍 41
    :kotlin: 12
    n
    g
    • 3
    • 2
  • b

    Björn Mayer

    11/17/2020, 10:12 AM
    Do Fun Interfaces work with extension functions?
    fun interface PropHandler<P> {
        fun P.handle(): Unit
    }
    :yes: 1
    k
    a
    • 3
    • 6
  • a

    Andrea Giuliano

    11/17/2020, 11:53 AM
    isn’t it possible anymore to invite members from slack app directly?
    m
    a
    l
    • 4
    • 5
  • e

    elect

    11/17/2020, 2:36 PM
    what's the annotation for functions with same signature but return type?
    n
    l
    • 3
    • 6
  • d

    Dan Newton

    11/17/2020, 4:10 PM
    Curious what other peoples opinions are for this. My team and I are considering using Java interfaces instead of Kotlin interfaces for our public APIs while working on a library that can be heavily used by both. The main reason for using Java interfaces is to ensure that Java is a first class citizen and to make it harder for us to rely on Kotlin’s syntactic sugar that can lead to APIs that are annoying to use from Java. Yes, there are rules we can put in place to make sure our API is easy to use from Java but I would argue its harder to follow these instead of 1 rule of “all public api interfaces in Java!“. This could also make it easier to onboard new developers as the one rule is easier to follow. Interested to hear what others think.
    c
    c
    +6
    • 9
    • 28
  • b

    bbaldino

    11/17/2020, 6:10 PM
    I'm trying to upgrade a maven project to kotlin 1.4, but it depends on a lib using kotlin 1.3 and I'm getting complaints about
    Runtime JAR files in the classpath should have the same version
    . Is it possible to depend on a 1.3 lib in a 1.4 project? Should I be setting the kotlin-stdlib dependencies in the 1.3 project to
    compile
    scope or something?
    • 1
    • 1
  • s

    Slackbot

    11/17/2020, 6:28 PM
    This message was deleted.
    g
    s
    h
    • 4
    • 5
  • d

    dMusicb

    11/17/2020, 6:32 PM
    What would be correct way to hash a unique string that can potentially be too long for the place it's stored, but still wanting to guarantee uniqueness to a high precision? I am currently trying to pass the unique string into a murmur3 128 bit hash, and it gives two 64 bit longs as the output. I wanted to then convert this to Base64 which the method I'm using requires a byte array, can I just do something like
    encodeToString("${long1}${long2}".toByteArray())
    ?
    e
    v
    • 3
    • 4
  • r

    robstoll

    11/17/2020, 8:07 PM
    Is there a way to know if the type argument passed to a
    fun <reified T>
    is a nullable type? I am asking in the context of https://youtrack.jetbrains.com/issue/KT-8947 I would like to be able to do something like:
    fun <reified T> foo() = if(T::isNullable) "y" else "n"
    foo<Int?>() // returns y
    foo<Int>()  // return n
    a
    i
    • 3
    • 6
  • h

    Hanno

    11/17/2020, 8:55 PM
    Has anyone used https://github.com/avaje/avaje-inject with kotlin and wants to share experience? :) We consider moving away from micronaut and spring, so we could need a new di framework.
    n
    • 2
    • 2
  • s

    Sourabh Rawat

    11/18/2020, 5:40 AM
    what are some libraries used for code generation / parsing / compiler stuff in kotlin ?
    e
    • 2
    • 1
  • n

    Nathan Retta

    11/18/2020, 6:22 AM
    Anybody have thoughts on the performance of the following code block? I came across this in our project and I feel like this would not perform well
    inline fun <reified T> HashMap<String, T>.toAnalyticsBundle(): Bundle {
        val analyticsRegex = Regex(FirebaseAnalyticsManager.ANALYTICS_REGEX_STRING)
    
        return Bundle().apply {
            for (key in keys) {
                val value = this@toAnalyticsBundle[key]
                val firebaseKey = FirebaseAnalyticsManager.googleAnalyticsifyString(key, analyticsRegex)
                when (value) {
                    is Int -> this@apply.putInt(firebaseKey, value)
                    is Float -> this@apply.putFloat(firebaseKey, value)
                    is Double -> this@apply.putDouble(firebaseKey, value)
                    is Boolean -> this@apply.putBoolean(firebaseKey, value)
                    is Char -> this@apply.putChar(firebaseKey, value)
                    is String -> this@apply.putString(firebaseKey, value)
                    is Parcelable -> this@apply.putParcelable(firebaseKey, value)
                    is Serializable -> this@apply.putSerializable(firebaseKey, value)
                }
    
            }
        }
    }
    fun googleAnalyticsifyString(stringToConvert: String, regex: Regex = Regex(ANALYTICS_REGEX_STRING)): String {
        val charArray = stringToConvert.toLowerCase().replace(regex, "").toCharArray()
        for((index, char) in charArray.withIndex()) {
            if(char == ' ') {
                val nextCharIndex = index + 1
                if(nextCharIndex < stringToConvert.length) {
                    charArray[nextCharIndex] = charArray[nextCharIndex].toUpperCase()
                }
            }
        }
        return charArray
            .joinToString("")
            .replace(" ", "")
    }
    g
    • 2
    • 1
  • b

    Bernhard

    11/18/2020, 11:54 AM
    hi, I have to paginate some web api and stop after a request returns “more”: false. I’m currently looking at sequences and takeWhile stops immediately after the predicate returns false; is there a way to say: take from this sequence until you encounter something including that thing? Only solution I can think of is using a mutable local variable and set that to false after the takeWhile
    r
    k
    r
    • 4
    • 25
  • r

    ribesg

    11/18/2020, 2:49 PM
    What’s up with requests to Youtrack taking multiple eternities to get a response ? Painful to use right now https://youtrack.jetbrains.com/
    v
    n
    • 3
    • 5
  • c

    Cicero

    11/18/2020, 8:38 PM
    So, I was told that this slack would be the place to dig deeper into KMM, am I wrong?
    r
    • 2
    • 2
Powered by Linen
Title
c

Cicero

11/18/2020, 8:38 PM
So, I was told that this slack would be the place to dig deeper into KMM, am I wrong?
r

redenergy

11/18/2020, 8:54 PM
There is a #multiplatform channel so probably yes
c

Cicero

11/18/2020, 9:01 PM
Danke
View count: 1