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

    bjonnh

    04/05/2019, 10:26 PM
    Just discovered: https://github.com/rjaros/kvision
    r
    • 2
    • 1
  • g

    GarouDan

    04/06/2019, 3:42 AM
    Can I upgrade from IntelliJ
    2018.3.6
    to
    2019.1
    without reinstalling? Can
    Check Updates
    do this for me somehow?
    g
    g
    +2
    • 5
    • 6
  • j

    Javier

    04/06/2019, 12:07 PM
    Is there any way to check if a variable is val/var?
    e
    s
    p
    • 4
    • 9
  • b

    bombe

    04/06/2019, 12:09 PM
    Assign something to it, if that results in a compiler error, it’s a
    val
    .
    j
    • 2
    • 1
  • t

    turansky

    04/06/2019, 12:14 PM
    Is there standard Kotlin analog of Guava
    Sets.difference
    ? In Kotlin it will be:
    fun Set<T>.difference(other: Set<T>): Set<T>
    {
      return subtrack(other) + other.subtrack(this)
    }
    s
    • 2
    • 5
  • e

    ec

    04/07/2019, 10:02 AM
    Which one would you prefer?
    -.kt
    2️⃣ 4
    c
    • 2
    • 6
  • s

    scottiedog45

    04/07/2019, 4:45 PM
    What’s the go to kotlin library for testing application flow? I understand how to write basic unit tests in kotlin, and also how to mock api responses, for my app, but I need something that can assert “when this button is tapped this new activity/these UI elements is/are showing on the screen”, so I guess it translates to testing navigation.
    s
    • 2
    • 1
  • r

    Robert

    04/07/2019, 9:19 PM
    What JDK version does Kotlin support? Does it support JDK12? Would it give problems with libraries?
    m
    • 2
    • 1
  • s

    Smallville7123

    04/08/2019, 11:19 AM
    is there anyway to declare a parameter as modifiable without needing to do
    fun a(b : Int) {
        var c = b
        c = 5
    }
    d
    n
    +2
    • 5
    • 19
  • a

    amadeu01

    04/08/2019, 12:04 PM
    to be able to use kotlin contracts, do I have to use experimental flag?
    m
    p
    • 3
    • 5
  • a

    amadeu01

    04/08/2019, 1:00 PM
    Can I write contract inside an interface?
    g
    • 2
    • 5
  • k

    kartikpatodi

    04/08/2019, 3:02 PM
    How does Kotlin support reification if it is not supported by JVM
    c
    m
    • 3
    • 19
  • d

    Dias

    04/08/2019, 4:00 PM
    don't people find it confusing that
    Any?.toString()
    returns "null" rather than actual null?
    🤣 2
    :yes: 4
    🇳🇴 8
    r
    g
    +4
    • 7
    • 20
  • k

    karelpeeters

    04/08/2019, 4:02 PM
    It doesn't?
    x?.toString()
    can return
    null
    ,
    x.toString where x:Any?
    will return
    "null"
    instead.
    r
    • 2
    • 6
  • x

    xenoterracide

    04/08/2019, 6:28 PM
    is there a reflective way to copy A to B in kotlin (where A and B are different instances of different classes but share the same attributes)
    d
    b
    • 3
    • 4
  • s

    Smallville7123

    04/08/2019, 11:53 PM
    how can i add an item to an AbstractList?
    kotlin.collections.EmptyList cannot be cast to Kpp_gradle$1$1$1$a
    fun <E> addOne(v: AbstractList<E>) {
        v.add(listOf<E>() as E)
    }
    
    class a {
        val empty : Int = 0
    }
    
    fun ret() {
        val f = arrayListOf<a>()
        f.add(a())
        println("type of f is ${f.javaClass}")
        println("type of f[0] is ${f[0].javaClass}")
        addOne(f)
        println("type of f is ${f.javaClass}")
        println("type of f[1] is ${f[1].javaClass}")
        abort()
    }
    s
    s
    • 3
    • 15
  • n

    nwh

    04/09/2019, 1:12 AM
    I'm upgrading from coroutines 0.3.0 to a 1.x version - how do I make IntelliJ replace usages for me? I could have sworn it offered to on another project, but I'm not getting it this time around First I switched my Kotlin version to
    1.3.0
    (rebuilt), then coroutines to
    1.0.0
    , and received no offer for automatic conversion EDIT: Found an alt-enter option to fix it, nevermind
    l
    • 2
    • 1
  • m

    Mike

    04/09/2019, 2:16 AM
    You don’t have to put it in an object. You can just do it at the top-level of a file. But do note that if they aren’t explicitly in an object/class, that Kotlin will create a class that is the filename + kt appended to it. Also,
    const
    will get inlined by the compiler in your Kotlin code, but will also be static so they can be accessed from Java.
    f
    • 2
    • 1
  • t

    tipsy

    04/09/2019, 6:37 AM
    is it possible to use coroutines internally, but wrap them in a future to pass the result to java?
    fun myFutureFunction(): ComleteableFuture<String> {
        // convert here?
        return ... myCoroutineFunction();
    }
    
    fun myCoroutineFunction() {
        // ... do most things here
    }
    g
    • 2
    • 3
  • g

    gregorbg

    04/09/2019, 6:56 AM
    Generics 101: I have two interfaces that work together like this:
    interface FancyConnector<T : Transcoder<I, O>> : RawHttpConnector {
        val transcoder: T
    
        fun send(entity: I) = sendRaw(this.transcoder.encode(entity))
        fun receive(): O = this.transcoder.decode(receiveRaw())
    }
    
    interface Transcoder<I, O> {
        fun encode(entity: I): HttpBytes
        fun decode(raw: HttpBytes): O
    }
    How can I make the compiler recognise the
    I
    and
    O
    type generics? Or alternatively, how can I define my interfaces so that
    FancyConnector
    doesn't need to know the internal types of
    Transcoder
    ? EDIT: Imagine there is a
    class IdentityTranscoder<E> : Transcoder<E, E>
    . I want to be able to use it like
    class MyConnector<IdentityTranscoder<Foo>>
    instead of having to specify
    class MyConnector<Foo, Foo, IdentityTranscoder<Foo>>
    s
    • 2
    • 6
  • g

    ghedeon

    04/09/2019, 8:11 AM
    But why?
    s
    a
    • 3
    • 6
  • s

    Smallville7123

    04/09/2019, 8:43 AM
    apparently i found a bug 0.0
    [18:05:11] <macropreprocess> Reason:       Type 'java/lang/Object' (current frame, stack[1]) is not assignable to 'java/lang/Integer'     Current Frame:       bci: @111       flags: { }       locals: { 'java/util/ArrayList', 'java/lang/String' }       stack: { 'java/lang/StringBuilder', 'java/lang/Object', null }
    [18:08:13] <Bombe> Please go back to coding C.
    [18:08:13] <Bombe> Java is obviously not for you.
    [18:08:13] <yawkat> macropreprocess: tf are you doing to get that error?
    [18:08:13] <yawkat> can you paste youre code?
    [18:08:13] <yawkat> your*
    [18:08:38] <Bombe> That’s not code.
    [18:36:58] <macropreprocess> yawkat: <https://bpaste.net/show/bf6b86553f0a>
    [18:37:13] <macropreprocess> wait no
    [18:38:27] <macropreprocess> <https://bpaste.net/show/91122a1a2a5e>
    [18:38:31] <macropreprocess> yawkat: 
    [18:39:49] <yawkat> yea that looks like a bug
    [18:41:29] <macropreprocess> oh
    [18:41:37] <macropreprocess> yay i found a bug
    🏅 2
    g
    • 2
    • 2
  • g

    Giorgio Antonioli

    04/09/2019, 1:44 PM
    Given a boolean condition I want to return an object if that expression returns
    true
    . Is there a shorter way (in the stdlib maybe) to write the following?
    someBooleanCondition.takeIf { true }?.let { "dummy-string" }
    E.g. (in pseudo-code)
    someBooleanCondition.ifTrue { "dummy-string" }
    d
    w
    +4
    • 7
    • 11
  • j

    Jukka Siivonen

    04/09/2019, 4:49 PM
    Anyone familiar with validation using JSR-303 annotations ? I'm not sure if this is Kotlin related but I'm having difficulties defining my annotations using interface EDIT: Workaround is to use @JvmDefault on interface method
    f
    r
    • 3
    • 20
  • d

    dmcg

    04/09/2019, 6:14 PM
    Does anyone know how to reference the receiver in an extension function when I'm stopped in the debugger? Neither
    this
    nor
    $receiver
    seem to be it.
    a
    • 2
    • 2
  • r

    robstoll

    04/09/2019, 6:30 PM
    Are there utilities to get a minimalised version of kotlin-std and kotlin-runtime? In the sense of dead code elimination or jigsaw ?
    k
    d
    • 3
    • 3
  • s

    snowe

    04/09/2019, 7:46 PM
    is there a simpler way of writing this class? I feel like my coworker could just use lateinit, but I don't know if jsonproperty allows that...
    -.kt
    b
    f
    • 3
    • 21
  • r

    Robert

    04/09/2019, 8:51 PM
    I have a
    build.gradle.kts
    k
    a
    • 3
    • 9
  • j

    Jukka Siivonen

    04/10/2019, 8:27 AM
    Is it possible to define annotation that is composed or inherited from other annotations?
    d
    • 2
    • 10
  • b

    Bernhard

    04/10/2019, 9:39 AM
    is there a better way to do something like: if(isBlankOrNull(string))
    d
    b
    • 3
    • 5
Powered by Linen
Title
b

Bernhard

04/10/2019, 9:39 AM
is there a better way to do something like: if(isBlankOrNull(string))
d

diesieben07

04/10/2019, 9:41 AM
string.isNullOrBlank()
b

Bernhard

04/10/2019, 9:41 AM
thank you!
I suppose creating methods on nullable types requires you to use extension functions right?
d

diesieben07

04/10/2019, 9:44 AM
Yes
b

Burkhard

04/10/2019, 9:44 AM
Yes, it does.
fun String?.isNullOrBlank() = ...
View count: 3