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

    christophsturm

    12/19/2018, 12:29 PM
    is it possible to copy a
    Random
    instance? or do i have to store the seed and create it from that again?
    e
    a
    i
    • 4
    • 20
  • r

    Ruckus

    12/19/2018, 4:43 PM
    I noticed the docs on random (https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.random/-random/index.html) say:
    The companion object Random.Companion is the default instance of Random.
    But isn't the companion object
    Random.Default
    ?
    i
    • 2
    • 1
  • r

    Ruckus

    12/19/2018, 5:21 PM
    You would need to define a custom
    operator fun contains
    object Links {
        <values here>
    
        operator fun contains(link: String) = when (link) {
            HELP, SHOP, BLOG, ... -> true
            else -> false
        }
    }
    👍 1
    s
    j
    +2
    • 5
    • 18
  • t

    Tasos Stamadianos

    12/19/2018, 8:49 PM
    Hi all, the following code snippet doesn't compile due to the possibility of an unchecked null, even though I'm definitely accommodating for null. This is a cut down version of the issue when I found it in my code base. Is there something I'm overlooking? The associated error:
    try-catch-null-check.kt:22:24: error: operator call corresponds to a dot-qualified call 'nullableVal.plus(1)' which is not allowed on a nullable receiver 'nullableVal'.
    	val sum = nullableVal + 1
                           ^
    try-catch-null-check.kt
    r
    d
    • 3
    • 13
  • g

    ghedeon

    12/19/2018, 9:07 PM
    An example with
    ::
    (bound callable reference?). Any way to properly import
    Companion
    so I don't see it in the code?
    class Foo(bar: () -> Bar)
    
    class Bar {
        companion object {
            fun newInstance() = Bar()
        }
    }
    ....
    Foo(Bar.Companion::newInstance) //<--- works
    Foo(Bar::newInstance) //<--- doesn't work
    r
    • 2
    • 3
  • d

    Dominaezzz

    12/19/2018, 9:11 PM
    I have two identical inline extension functions on
    Collection<...>
    . The only difference is one is on
    Collection<String>
    and the other is
    Collection<Closeable>
    . IntelliJ complains they have the same signature on JVM (because type erasure). Even though they are inline functions?
    s
    i
    • 3
    • 4
  • j

    jdemeulenaere

    12/19/2018, 9:54 PM
    Has anyone experimented with serverless applications in Kotlin (e.g. with knative or AWS Lambda)? If so, with what "flavour" of Kotlin (JVM, JS, Native) ? And is the performance acceptable for the serverless world (especially for Kotlin JVM that has worse warm up time) ?
    n
    c
    u
    • 4
    • 6
  • d

    Dalinar

    12/20/2018, 9:54 AM
    when I get a warning lambda argument should be moved out of parentheses is that just for aesthetics? or will there be some possible issues if I don't do that?
    a
    a
    • 3
    • 2
  • d

    Dias

    12/20/2018, 10:54 AM
    hello, given that you can extend subclass of a sealed class anywhere else, doesn't it kinda defeat the purpose of a sealed class? you cannot tell anymore if you covered all subclass of a sealed class, and
    when
    expression for example becomes non-exhaustive
    💯 1
    🇳🇴 1
    g
    • 2
    • 1
  • k

    karelpeeters

    12/20/2018, 10:55 AM
    You can be sure you covered all direct subclasses, and so you `when`s definitely stay exhaustive.
    d
    d
    • 3
    • 3
  • r

    reik.schatz

    12/20/2018, 11:57 AM
    if I have an
    Array<String>?
    and a
    String?
    and I need to merge the two and return
    Array<String>?
    - is there a better way than to have a bunch of if-else checking for
    null
    (if both are null it should return null also)?
    m
    • 2
    • 4
  • r

    ribesg

    12/20/2018, 12:32 PM
    Quick question, how do I get an instance of
    Class<Map<String, Any>>
    without creating an empty map?
    d
    a
    • 3
    • 4
  • x

    xenoterracide

    12/20/2018, 1:00 PM
    where's the right place to request features?
    m
    a
    • 3
    • 4
  • i

    Ilias Yahia

    12/20/2018, 2:10 PM
    I have a question: when using Koltin to solve problems in LeetCode, but the runtime is way higher than the Java runtime for the same solution, any idea why?
    👍🏼 1
    a
    m
    • 3
    • 5
  • r

    Ruckus

    12/20/2018, 8:39 PM
    Any
    🤦 1
    m
    a
    • 3
    • 13
  • p

    paulex

    12/21/2018, 1:53 AM
    Morning, please im looking at writing a real time video stream application. mobile + server(kotlin) + web But I'm not sure on what will be an ideal path to follow, ive read a few things on kafka + spark(awesome stuff), but I think, they probably don't address my need or are overly complex for what I want to achieve.. I was hoping I could get a little heads up.
    g
    s
    • 3
    • 3
  • d

    Dalinar

    12/21/2018, 6:39 AM
    what's the secret to paste-convert java to kotlin?
    g
    d
    • 3
    • 7
  • m

    Marcelo Velloso

    12/21/2018, 2:36 PM
    I hope this is the right channel for this, first time poster. I have a question on coroutines. I want to launch two coroutines asynchronously and wait on whichever completes first, is this possible? The context here is that two separate server calls can be made independently and if either returns an error I want to cancel the remaining coroutine and error out.
    e
    • 2
    • 2
  • h

    hhariri

    12/21/2018, 3:01 PM
    <!here> Most Helpful Slack Community Member With 2018 coming to an end, we’d like to take the opportunity to say thank you to each and every one of you that make up our Slack community. Despite nearly tripling in size this year, we still remain a very welcoming and helpful place. And this is because you all make it possible. As a special recognition, we would like to give an award to “The Most Helpful Slack Community Member”. The Rules In the thread for this message, mention the person (or upvote them with +1 if already mentioned) who has helped you most in learning Kotlin. We will then narrow down the list to the top 10. These will enter our final round where you will be able to vote for them. Please note that JetBrains employees cannot be nominated. The Timeline Nominations can be made as of now till December 26, 23:59 CET. The Finals will take place on December 27 from 12PM CET and last 24 hours. The winner will be announced on December 28 at 5PM CET.
    :kotlin: 18
    :kotlin-flag: 10
    🎉 47
    ✊ 5
    c
    k
    +23
    • 26
    • 42
  • t

    tschuchort

    12/21/2018, 4:29 PM
    I am playing around with the compiler (
    K2JVMCompiler
    ) and noticed that I can compile files using the
    java.*
    packages even if the option
    -no-jdk
    is used. How can that happen? Surprisingly it works if the host project JDK is version 9 but not with version 8, even though it shouldn't make a difference since the compiler doesn't have access to the host process' classpath (and doesn't log loading any jdk modules as it normally would)
    a
    • 2
    • 2
  • d

    Dalinar

    12/21/2018, 6:01 PM
    what's the easiest way to remove the first element from the
    List
    returned by
    val lines = reply.split("\n")
    ?
    s
    r
    • 3
    • 4
  • s

    Strum355

    12/21/2018, 6:02 PM
    Is there a way to have compiler enforced "abstract static methods" for kotlin, be it in an interface or an abstract class? Perhaps similar to a factory style but id rather not have <ConcreteType>Factory for all the concrete types
    l
    • 2
    • 1
  • g

    groostav

    12/21/2018, 7:54 PM
    This smart casting thing, the more I think about it the more work it becomes:
    fun `kotlin is pretty smart`(){
        val nullableSet: Set<Int>? = setOf(1, 2, 3)
        
        when(nullableSet?.size){ 
            null -> {}
            else -> { nullableSet.first() }
        }
    }
    I would've thought that I'd need a
    nullableSet!!
    in the second case. does that mean the smart-cast system was able to infer that
    well the expression
    nullableSet?.size
    wasn't null, and
    size
    can never be null, so
    nullableSet
    must also not be null, so I can smart-cast it to
    Set<Int>
    if so, that kotlinc is one sharp cookie
    d
    s
    • 3
    • 2
  • r

    Ruckus

    12/21/2018, 10:47 PM
    This seems like a pretty basic question, but it's just not clicking for some reason. Say I have
    class Ref<T: Ref<T>> { ... }
    class RefHolder<T: Ref<T>> { ... }
    
    class Source {
        val refs: MutableList<RefHolder<*>> = ...
        ...
    }
    
    fun <T: Ref<T>> serializeRef(ref: RefHolder<T>, ...): ... { ... }
    
    fun serializeSource(source: Source): ... {
      val refs = source.refs.map { serializeRef(it, ...) }  // Cannot resolve type as it: Ref<*>
    }
    How do I make it so I can call
    serializeRef
    ?
    d
    • 2
    • 5
  • r

    Ruckus

    12/21/2018, 10:56 PM
    I'm getting around it using
    serializeRef(it as RefHolder<Nothing>, ...)
    which works due to erasure, but it feels wrong and dirty.
    a
    • 2
    • 2
  • w

    Will Harrison

    12/21/2018, 11:00 PM
    If I have a list of objects called
    entries
    and wanted to create another list from
    entries
    by running each item through a method to do some conversions, could I do it using the
    list.map{ ... }
    function or do I just need to loop through and add each one individually
    r
    • 2
    • 2
  • j

    Johan Vergeer

    12/22/2018, 1:11 PM
    Maybe a strange question, but does anyone know if JetBrains is working on making Kotlin compatible with C#
    s
    a
    +3
    • 6
    • 11
  • o

    otakusenpai

    12/22/2018, 1:31 PM
    which version of intellij does kotlin support nowadays
    s
    • 2
    • 13
  • o

    otakusenpai

    12/22/2018, 1:32 PM
    ive been out of touch for a while...exams were going on
    g
    • 2
    • 1
  • j

    Johan Vergeer

    12/22/2018, 5:08 PM
    Does anyone know how to get the names of all implementations of an interface in Kotlin?
    k
    • 2
    • 1
Powered by Linen
Title
j

Johan Vergeer

12/22/2018, 5:08 PM
Does anyone know how to get the names of all implementations of an interface in Kotlin?
k

karelpeeters

12/22/2018, 6:06 PM
https://stackoverflow.com/questions/347248/how-can-i-get-a-list-of-all-the-implementations-of-an-interface-programmatically
View count: 4