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

    basher

    06/03/2020, 11:38 PM
    Is there a software license listed somewhere for the kotlin standard library?
    c
    • 2
    • 1
  • a

    Andrew

    06/04/2020, 12:15 AM
    Is there any way to suspend until some predicate is met, other than like a while loop?
    z
    • 2
    • 5
  • e

    elect

    06/04/2020, 11:37 AM
    I have
    tasks.withType(JmhTask::class.java) { }
    where
    tasks
    is a
    TaskContainer
    type, which extends
    interface DomainObjectCollection<T>
    DomainObjectCollection<T>::withType
    is defined as
    <S extends T> DomainObjectCollection<S> withType(Class<S> type, Action<? super S> configureAction)
    I'd like to type instead
    tasks<JmhTask> { }
    , so I wrote:
    inline operator fun <reified S> TaskContainer.invoke(configureAction: Action<in S>?) = withType(S::class.java, configureAction)
    but
    withType
    is marked red:
    None of the following functions can be called with the arguments supplied.
    withType(Class<TypeVariable(S)!>, Action<in TypeVariable(S)!>)   where S = TypeVariable(S) for    fun <S : Task!> withType(type: Class<S!>, configureAction: Action<in S!>): DomainObjectCollection<S!> defined in org.gradle.api.tasks.TaskContainer
    z
    • 2
    • 2
  • d

    darkmoon_uk

    06/04/2020, 11:59 AM
    When any IntelliJ-family IDE calls out to external tools such as Gradle; Why does it not log the actual command passed to that tool, in the console (so that it appears just above the tool output)? This would be extremely useful both for learning what's going on under the hood, and for diagnosing problems. I'm currently facing an issue where a Gradle build succeeds from the command line but fails inside the IDE. It's hard to see what the underlying difference is.
    c
    c
    m
    • 4
    • 4
  • m

    Mike

    06/04/2020, 12:00 PM
    Is there a standard imaging library for kotlin? Something that would allow me to build up images and save the in various formats? Perhaps do some light image processing?
    d
    e
    +2
    • 5
    • 5
  • u

    user

    06/04/2020, 3:30 PM
    message has been deleted
    m
    c
    • 2
    • 5
  • a

    Antoine Gagnon

    06/04/2020, 4:10 PM
    Hey everyone, very basic question but I can’t figure out if there’s a native kotlin function to do something like this where I want to get a list of the numbers in originalNumbers that are not in newNumbers
    val originalNumbers = listOf(1,3,5,6,8,235,764)
    val newNumbers = listOf(1,4,6,235,764,23)
    val toRemove = originalNumbers.filter { it !in newNumbers } // [3, 5, 8]
    This work perfectly fine, but just for my own peace of mind I feel like there’s a collections functions that would do exactly that?
    s
    • 2
    • 3
  • s

    Sam Garfinkel

    06/04/2020, 4:11 PM
    What are folks using for XML databinding in Kotlin? JAXB, Jackson, something else?
    j
    r
    • 3
    • 5
  • w

    william

    06/04/2020, 6:04 PM
    Hi kotlin peeps, I'm getting stuck on some java kotlin interop. I have some android code (in java) that I am interacting with that simplifies to this:
    public class FooService {
        public void addFoo(Foo foo) {
            // woop
        }
    
        public void removeFoo(Foo foo) {
            // womp
        }
    }
    interface Foo {
        void callback();
    }
    and then in the kotlin code I have:
    class FooKotlin {
        fun buzz() {
            val fooService = FooService()
            fooService.addFoo {
                // do some callback stuff
    
                fooService.removeFoo(???)
            }
        }
    }
    I'm not sure what to replace the
    ???
    with in order to remove the callback listener after it has executed once
    z
    • 2
    • 6
  • d

    Draget

    06/04/2020, 8:34 PM
    Does anyone know an article or something similar that gives a technical comparison of Kotlin to C#?
    j
    e
    • 3
    • 6
  • k

    Kenneth Endfinger

    06/04/2020, 10:03 PM
    Is anyone else seeing this when trying to upgrade to the 1.4 EAP Plugin
    :yes: 6
    z
    i
    • 3
    • 4
  • n

    NurBahnhof

    06/05/2020, 12:19 AM
    What is the order of function returned by val KClass<*>.memberFunctions: Collection<KFunction<*>> , is it the order of declaration?
    r
    g
    • 3
    • 3
  • a

    andyg

    06/05/2020, 6:17 AM
    Hi, is it possible to create a
    when
    statement dynamically from a map, or two arrays/lists? something like
    val teamMap : Map<String, String> = mapOf("Yankees" to "baseball", "Cowboys" to "football", "Lakers" to "basketball")
    val sport : String = when {
      teamMap.map { e -> mystring.contains(e.key) -> e.value }
    }
    also a value for
    else
    would need to be supplied, not sure the best way
    e
    • 2
    • 2
  • b

    Brian Dilley

    06/05/2020, 7:16 AM
    I wrote some Skia wrappers for Kotlin, full GPU support, off screen, etc - I wonder if people would be interested.
    👀 1
    💪 1
    l
    m
    • 3
    • 2
  • g

    Gilles Barbier

    06/05/2020, 11:39 AM
    Hi all, I'm using operator overloading and have issues with inheritance, with
    open class MyInt(open var int: Int = 0) : {
        operator fun plus(increment: Int): MyInt = MyInt(int + increment)
    }
    I can do
    MyInt(4) + 3
    It works. But now, I would like to extends
    MyInt
    class OtherInt(override var int: Int = 0) : MyInt(int)
    I can do
    OtherInt(4) + 3
    but the output is a
    MyInt.
    Is there a way for
    OtherInt
    to benefit from operator overloading without reimplementing it in it?
    d
    • 2
    • 29
  • r

    rrva

    06/05/2020, 11:48 AM
    if I do a
    when
    over a type system, like when { foo is A -> foo is B -> } why can the compiler not figure out compile-time if the when is exhaustive without an else branch?
    d
    m
    s
    • 4
    • 6
  • d

    Daniel Svensson

    06/05/2020, 11:58 AM
    I was thinking about
    foo.let(Bar::method)
    vs
    foo.let { Bar.method(it) }
    in terms of compiler speed, thinking that the function reference opens up to fewer possibilities compared to a block, and it could have a slight, but measurable compilation speedup if used a lot. Generating a 1000 long file with identical
    .let { .. }
    and another file with
    .let(func::ref)
    resulted in
    .let { ... }
    being consistently slightly faster with 7.125 seconds vs 7.882 seconds. One hypothesis is that the function reference version is transformed to the block version during compilation, perhaps someone here knows more of the compiler internals to pitch in on that. As expected identical byte code is generated in both cases. When I then tried with Kotlin 1.4 M2, it turned out that the
    .let { ... }
    version had become slower, and has now consistently the exact same compilation speed as the function reference. Which is the reason to why I signed up to this slack 🙂 Was hoping for the opposite as 1.4 is touted to improve compilation speed (but it's not like it's life or death which style is preferred).
    z
    k
    • 3
    • 5
  • r

    Ryan

    06/05/2020, 1:35 PM
    Why are data classes so slow when instantiating them in intellij? My cursor locks up while typing
    a
    • 2
    • 4
  • p

    poohbar

    06/05/2020, 4:43 PM
    How can I get a Java
    Class
    from a
    KClass
    ? For example I have
    KClassImpl "class kotlin.String"
    and I want to get Java’s
    String.class
    from it I tried:
    JvmClassMappingKt.getJavaClass(klass)
    but it returns
    class kotlin.reflect.jvm.internal.KClassImpl
    😕
    s
    j
    c
    • 4
    • 9
  • s

    Sam Garfinkel

    06/05/2020, 5:49 PM
    Is there a way with reified generics to handle
    T: Any?
    differently from
    T: Any
    without conflicting overloads? The following conflict:
    inline fun <reified T: Any> foo(): Bar<T> {}
    inline fun <reified T: Any, S: T?> foo(): Bar<S> {}
    Which makes sense since it’s ambiguous for the call when T is non-null.
    l
    • 2
    • 1
  • h

    Hullaballoonatic

    06/05/2020, 10:34 PM
    is
    companion object
    the kookiest kotlin-specific syntax for a typical OOP language feature? y/y?
    c
    j
    +2
    • 5
    • 14
  • j

    juan torres

    06/06/2020, 1:53 AM
    I’m not sure if this is the best channel to post this, but here it is: I just started with kotlin (2-3 months ago), and to learn it I took on a fun project based on this programming challenge, LambdaSharp / LambdaRobots*.* I will be sharing the kotlin challenge with my team next week (mostly java and python devs) to introduce them to kotlin and AWS Lambda. I am looking for a handful of volunteers to help me test-run the challenge and get some feedback.
    • 1
    • 2
  • j

    Javier

    06/06/2020, 2:16 PM
    I am getting this error after upgrading Kotlin to 1.4 m2
    e: java.lang.IllegalStateException: Backend Internal error: Exception during file facade code generation
    • 1
    • 4
  • a

    Animesh Sahu

    06/07/2020, 5:46 AM
    I have some confusion over the type system, could anybody clarify what is meant by
    {Comparable<{ Double & Int }> & Number}
    https://stackoverflow.com/questions/62241262/understanding-kotlin-type-system-what-is-meant-by-comparable-double-int
    e
    • 2
    • 2
  • d

    Davide Giuseppe Farella

    06/07/2020, 6:46 AM
    Is there any trick for declare an extension ONLY for nullable type?
    class MyClass<T>
    
    MyClass<String?>().myExtension()  // -> OK
    MyClass<String >().myExtension()  // -> Does not compile?
    d
    z
    • 3
    • 4
  • e

    E.Kisaragi

    06/07/2020, 3:58 PM
    what does
    Foo!!
    mean??
    f
    h
    +3
    • 6
    • 11
  • h

    Hamza

    06/08/2020, 6:22 AM
    why cant you have a
    suspend
    and an
    operator
    fun?
    p
    z
    • 3
    • 7
  • p

    Patrick Lannigan

    06/08/2020, 10:58 AM
    It seems like the compiler's null tracking doesn't work when the type of the variable is a function and the variable is an instance variable on a class.
    fun thing(a: ((String) -> String)?) {
        if (a == null) {
            println("null")
        } else {
        	println(a("hello"))
        }
    }
    
    class Thing(private val a: ((String) -> String)?) {
        fun thing() {
            if (a == null) {
                println("null")
            } else {
                // Reference has a nullable type '((String) -> String)?', use explicit '?.invoke()' to make a function-like call instead
            	println(a("hello"))
            }
        }
    }
    Reproducing the issue using the playground
    m
    k
    • 3
    • 8
  • m

    Michael de Kaste

    06/08/2020, 12:40 PM
    Is it possible to show compile time values within the code passively. consider this piece of code:
    if(yourValue == SOME_VALUE)
    where SOME_VALUE is a const val defined in an interface. Can I show the value of this value passively like inferred types are passively shown in the code?
    ➕ 2
    z
    • 2
    • 2
  • j

    jeggy

    06/08/2020, 4:26 PM
    What's the difference in having
    implementation(kotlin("stdlib"))
    and
    implementation(kotlin("stdlib-jdk8"))
    ?
    c
    c
    m
    • 4
    • 6
Powered by Linen
Title
j

jeggy

06/08/2020, 4:26 PM
What's the difference in having
implementation(kotlin("stdlib"))
and
implementation(kotlin("stdlib-jdk8"))
?
c

Casey Brooks

06/08/2020, 4:28 PM
This article explains the differences pretty well https://medium.com/@mbonnin/the-different-kotlin-stdlibs-explained-83d7c6bf293
👍 1
j

jeggy

06/08/2020, 4:32 PM
Thanks 🙂 As I'm running on Java11 on a server. It should be fine for me to use use
stdlib-jdk8
?
c

Casey Brooks

06/08/2020, 4:34 PM
Yeah, that should be fine. They don’t have stdlib versions past 8, but that one should work just fine. I have projects using
stdlib-jdk8
and running tests on JDKs 8 through 13 with no issues
j

jeggy

06/08/2020, 4:35 PM
Perfect. Thanks for the answers 👍
c

christophsturm

06/08/2020, 5:11 PM
maybe it should be called jdk8+
m

Mike

06/15/2020, 9:11 PM
It leverages features that were added in jdk8, hence the name. So Lambda's etc. Those still exist in 9, 10 etc, so it's still applicable, and those features haven't been superseded by anything in later JDK's. There haven't been jdk9, jdk10 etc versions as there hasn't been anything added to the bytecode that they've wanted to take advantage of in the stdlib.
View count: 2