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

    Brian Dilley

    12/08/2020, 4:28 AM
    i guess if i want Java projects to be able to use it - i’d have to.
    c
    l
    • 3
    • 3
  • n

    Nir

    12/08/2020, 3:58 PM
    Is it possible to make something like
    run
    or
    with
    work with an enum class? basically a way to introduce a scope where we can reference the enumerators without qualification
    s
    w
    • 3
    • 22
  • d

    diesieben07

    12/08/2020, 4:17 PM
    Is it somehow possible to have smart casts with type parameters? I have a situation where I have
    interface Base<T>
    and
    Concrete<T : Any> : Base<T>
    . In a method which accepts
    Base<T>
    I now need to check
    is Concrete<T>
    , but that's impossible because in the method
    T
    is not constrained to
    Any
    (but it has to be, if I have a
    Concrete<T>
    ... See thread for more code.
    c
    s
    • 3
    • 8
  • x

    xetra11

    12/08/2020, 10:54 PM
    I am trying to use
    File.walk
    however I am not able to get it resolved. IntelliJ always shows me
    java.nio.file.Files.walk
    instead of the extension
    public fun File.walk(direction: FileWalkDirection = FileWalkDirection.TOP_DOWN): FileTreeWalk =
        FileTreeWalk(this, direction)
    c
    • 2
    • 8
  • n

    Nish Patel

    12/09/2020, 1:08 AM
    Hi guys, I would like to ask you that how could we check if the list is null only, the list could be empty that's fine but shouldn't be null, could someone help me?
    z
    n
    d
    • 4
    • 10
  • m

    Martin Barth

    12/09/2020, 7:08 AM
    What have I done wrong:
    private fun <Long> List<Long>.combinationSums(): Sequence<Long> {
        val list = this
        return sequence {
            for (i in 0 until list.count()) {
                for (j in i + 1 until list.count()) {
                    val sum: Long = list[j] + list[i]
                    yield(sum)
                }
            }
        }.distinct()
    }
    I am getting a compiler error for the `list[i] + list[j]:
    Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: 
    public inline operator fun BigDecimal.plus(other: BigDecimal): BigDecimal defined in kotlin
    public inline operator fun BigInteger.plus(other: BigInteger): BigInteger defined in kotlin
    public operator fun <T> Array<TypeVariable(T)>.plus(element: TypeVariable(T)): Array<TypeVariable(T)> defined in kotlin.collections
    j
    n
    • 3
    • 5
  • c

    christophsturm

    12/09/2020, 10:40 AM
    is there a trick to make overriden fields not null? for example in my own RuntimeException subclasses i want message to be String and not String?. actually, in this example the compiler could infere that message is not nullable for all subclasses of ApplicationException, or am I missing something?
    open class ApplicationException(message: String, cause: Throwable?) : RuntimeException(message, cause)
    e
    • 2
    • 7
  • r

    rtsketo

    12/09/2020, 10:53 AM
    Let's say I have two functions:
    ImageView.photo(url: String) = { .. }
    photo(url: String) = { .. }
    Is there a way to call the second one in the scope of an ImageView like below?
    ImageView(context).apply {
        ...
        photo(url)
        ...
    }
    d
    • 2
    • 2
  • j

    Jason

    12/09/2020, 12:13 PM
    Any help ?
    a
    • 2
    • 4
  • s

    Sarah Gross

    12/09/2020, 3:23 PM
    Is there a way to generate any() objects for method params, so I don't end up with code that has a long list of any() in my test? It's not a vararg method, but maybe there's a way to use repeat or unpacking syntax?
    _whenever_(myMethod(
    _any_(), _any_(),_any_(), _any_(), _any_(), _any_(), _any_(), _any_())
    ).thenReturn
    j
    t
    • 3
    • 8
  • h

    hho

    12/09/2020, 5:30 PM
    Hi, what's the best way to generate Typescript definitions for some Kotlin data classes? (a bit like Dukat in reverse?)
    s
    l
    • 3
    • 4
  • b

    bod

    12/09/2020, 7:09 PM
    Hello, World! Isn't there a version of
    String.map
    fun that returns a String (instead of the generic one returning a List<R>) somewhere?
    a
    s
    n
    • 4
    • 18
  • h

    holgerbrandl

    12/09/2020, 8:28 PM
    Will there be a recording of tomorrow's kafka with kotlin webinar https://info.jetbrains.com/kotlin-webinar-december-10-2020.html ?
    a
    a
    • 3
    • 3
  • a

    André Benda

    12/09/2020, 9:22 PM
    Hi, does anyone else has problems with IntelliJ since the update to BigSur? In my case: after using the IDE for about 20 minutes my MacBook Pro (2019, i9) is running the IDE at 101 % CPU usage and the lag in the UI makes coding tedious.
    ✅ 1
    a
    s
    g
    • 4
    • 5
  • w

    wasyl

    12/09/2020, 10:08 PM
    I just found https://youtrack.jetbrains.com/issue/KT-24925, to allow short-hand notation for enum/sealed class values when the compiler can infer the type (so
    foo(.Baz)
    instead of
    foo(Foo.Bar.Baz)
    . It hope it’s considered for implementation in the relatively near future, would help greatly with verbosity!
    n
    • 2
    • 3
  • a

    allan.conda

    12/10/2020, 8:24 AM
    Is there a cleaner way to do this? I don’t need the reference to the
    stateDelegate
    aside from the constructing the backing field and the public read-only state
    // util
    inline operator fun <T> StateFlow<T>.getValue(thisObj: Any?, property: KProperty<*>): T = value
    inline operator fun <T> MutableStateFlow<T>.setValue(thisObj: Any?, property: KProperty<*>, value: T) {
        this.value = value
    }
    
    // usage
    private val stateDelegate: MutableStateFlow = MutableStateFlow(...)
    private var _state: State = stateDelegate
    val state: StateFlow<State> = stateDelegate
    
    fun foo() {
        _state = State(...)
    }
    • 1
    • 1
  • b

    Benjamin Vallet

    12/10/2020, 9:32 AM
    Is there a standard way to exchange json data (text) between Kotlin and a Python program ?
    m
    r
    • 3
    • 6
  • n

    Nikky

    12/10/2020, 10:15 AM
    is there a concurrent list/queue that can atomically return its content and clear itself afterwards ?
    a
    b
    • 3
    • 5
  • s

    sbeve

    12/10/2020, 12:16 PM
    Hello, can someone tell me what name it is showing for me? Sbeve or something else? I am new to slack
    s
    o
    • 3
    • 6
  • g

    GarouDan

    12/10/2020, 3:38 PM
    Hello all, please consider adding your thoughts into this issue: https://youtrack.jetbrains.com/issue/KT-43876
    r
    • 2
    • 4
  • r

    rocketraman

    12/10/2020, 4:14 PM
    I have a lazy transient property in a
    <http://java.io|java.io>.Serializable
    class. However accessing
    foo
    from
    @delegate:Transient val foo: Foo by lazy { }
    causes a NPE on deserialization. How can I create a lazy property that the VM does not try to serialize, but at the same time does the right thing?
    r
    g
    • 3
    • 9
  • s

    Scott Whitman

    12/10/2020, 7:18 PM
    Is there a way to check if something is an object vs. a class? For example, how could I create this if statement?
    sealed class Fruit {
        class Apple(val color: String) : Fruit()
        object Orange : Fruit()
    }
    
    fun main() {
        val list = listOf(Fruit.Apple("red"), Fruit.Orange)
        for (item in list) {
            if (/* item is object? */) /* do something */
            else /* do something else */
        }
    }
    m
    a
    +2
    • 5
    • 7
  • a

    Alfred Lopez

    12/10/2020, 7:51 PM
    Quick question: are annotation processing compiler-only or can they be at runtime as well? I can't seem to find an example of such.
    a
    • 2
    • 7
  • e

    earroyoron

    12/10/2020, 9:42 PM
    Maybe this is something "basic" but I had some argue with a colleague.... about the run scope function, when I do:
    val result = run { ... }
    result is not actually calculated there, but when is needed (lazy), isn't it? I know this is the usual behaviour when using a functional style but I couldn't find any reference to give a clear explanation to my colleague.
    n
    c
    v
    • 4
    • 23
  • s

    sbeve

    12/10/2020, 10:31 PM
    How do single devs meaning devs that work because they have just started or something make icons? do they make them themselves?
    l
    e
    • 3
    • 6
  • a

    andylamax

    12/11/2020, 1:33 AM
    Hello, I am creating a koltin lib t be used on the
    jvm
    . I am using a bunch of
    Deffered<*>
    for async calls, how do I extract and await the values of
    Defered<*>
    from Java code?
    v
    • 2
    • 2
  • a

    Andy Gibel

    12/11/2020, 3:09 AM
    Hi folks, can someone please tell me why the following isn't possible?
    object MoonWidgetInput
    object MoonWidgetOutput
    object MoonWidgetData
    
    abstract class BaseVehicle<INPUT, OUTPUT>
    
    abstract class BaseWidget<INPUT, DATA, OUTPUT>() {
        abstract var vehicle : BaseVehicle<INPUT, OUTPUT>
    }
    
    class MoonRover : BaseVehicle<MoonWidgetInput, MoonWidgetOutput>()
    
    class MoonWidget : 
        BaseWidget<MoonWidgetInput, MoonWidgetData, MoonWidgetOutput>(){
        override var vehicle = MoonRover()
    }
    e
    • 2
    • 13
  • m

    Martin Barth

    12/11/2020, 7:17 AM
    I want to build a "2D array", and set and change elements in it. I think a mutableList does not work well, because i cant not randomly set elements in it. It gives a index out of bound exception. Is there a autogrow option? or should i use a different data structure?
    o
    n
    • 3
    • 7
  • e

    elect

    12/11/2020, 8:27 AM
    if I try
    var cb = new Function1<? extends InputTextCallbackData, Boolean> (() -> true);
    then the
    extends
    complains
    Wildcard type '? extends imgui.classes.InputTextCallbackData' cannot be instantiated directly
    p
    • 2
    • 4
  • d

    Daniele Segato

    12/11/2020, 11:10 AM
    Why is callbackFlow still marked experimental? As far as I know this is the official way of wrapping another api emitting multiple value (register / unregister). If I want to write a library using
    callbackFlow
    does that mean that it may become binary incompatible in the future? Thanks.
    z
    l
    • 3
    • 7
Powered by Linen
Title
d

Daniele Segato

12/11/2020, 11:10 AM
Why is callbackFlow still marked experimental? As far as I know this is the official way of wrapping another api emitting multiple value (register / unregister). If I want to write a library using
callbackFlow
does that mean that it may become binary incompatible in the future? Thanks.
bonus question the doc say
try {
    sendBlocking(value)
} catch (e: Exception) {
    // Handle exception from the channel: failure in flow or premature closing
}
but I find it a bit unhelpful. when can sendBlocking fail? what am I supposed to do there? (aka = how should I handle it?)
z

Zach Klippenstein (he/him) [MOD]

12/11/2020, 4:02 PM
One way that call can fail if the channel is closed and you’re still trying to send to it from a different thread. If you’ve correctly set up your callback to be removed by using
awaitClose
, this is a race condition that might not happen very often.
d

Daniele Segato

12/11/2020, 5:11 PM
so basically I could catch + ignore the exception there.
z

Zach Klippenstein (he/him) [MOD]

12/11/2020, 5:35 PM
Yes, there’s an active bug for the issue that
offer
throws when the channel is closed instead of returning false.
If you look at the implementation of
Observable.asFlow()
, it catches this exception and even has a comment linking to the bug.
l

louiscad

12/14/2020, 2:48 PM
Here's why it's still experimental : https://github.com/Kotlin/kotlinx.coroutines/issues/974
There might be additional reasons, but this is a big one.
View count: 4