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

    pablisco

    06/15/2018, 9:40 AM
    Random thought. Is there a way to make the class generated from a file (i.e.
    Something.kt
    ->
    SomethingKt
    ) extend a particular type? 🤔
    n
    s
    • 3
    • 5
  • j

    jlleitschuh

    06/15/2018, 3:55 PM
    @orangy Interesting bug in the Kotlin Script Parser that might interest you: https://github.com/gradle/kotlin-dsl/issues/928 TL;DR: This code compiles in Kotlin scripts but throws an NPE at runtime:
    val first by tasks.creating {
      dependsOn(second)
    }
    val second by tasks.creating
    o
    • 2
    • 1
  • a

    Ayden

    06/15/2018, 6:48 PM
    The most awkward thing which I am facing right now is that I know how to code, but I don't know what does every line of code means. 😞
    g
    e
    k
    • 4
    • 4
  • i

    ikt

    06/16/2018, 6:40 AM
    I have a kotlin closure. I need to pass it as a Java Runnable.
    e
    • 2
    • 1
  • k

    karelpeeters

    06/16/2018, 12:38 PM
    `where`: https://kotlinlang.org/docs/reference/generics.html#upper-bounds
    d
    • 2
    • 1
  • a

    ashishkrishnan

    06/16/2018, 5:28 PM
    How is
    Any
    or
    Nothing
    type mapped at runtime?
    s
    c
    • 3
    • 18
  • k

    karelpeeters

    06/16/2018, 9:09 PM
    But
    (Any) -> Unit
    is a subtype of
    (String) -> Unit
    , so you're supposed to be able the always replace the latter with the former if something is taking it.
    g
    r
    • 3
    • 11
  • n

    nwh

    06/17/2018, 1:30 AM
    Is there an advantage to using coroutines in a single threaded context? Like an event loop with one thread (besides syntax)
    k
    • 2
    • 2
  • s

    Slackbot

    06/18/2018, 7:39 AM
    This message was deleted.
    o
    • 2
    • 1
  • a

    arekolek

    06/18/2018, 1:41 PM
    why doesn't this work?
    val defaultHandler: Consumer<in Throwable>? = RxJavaPlugins.getErrorHandler()
    checkNotNull(defaultHandler)
    defaultHandler.accept(Throwable()) // only safe or non-null asserted calls are allowed on nullable receiver of type...
    what's the point in this then:
    public inline fun <T:Any> checkNotNull(value: T?, lazyMessage: () -> Any): T {
        contract {
            returns() implies (value != null)
        }
    c
    g
    • 3
    • 3
  • e

    egorand

    06/18/2018, 2:07 PM
    do I have to checkout the precise git SHA that caused the crash to make this work?
    i
    • 2
    • 1
  • m

    mp

    06/18/2018, 3:22 PM
    hi there 1) have data class full nonnullable
    data class Info(val id: Int val name: String, val phone: Long)
    2) want to have
    data class InfoPayload(val id: Int? val name: String?, val phone: Long?)
    maybe with some kind of annotation
    @payloadable
    If no options - I want to ask about compilers plugins for kotlin: can any one share docs for implementation of kotlin-compiler-plugin? tnx
    k
    • 2
    • 1
  • m

    muralimohan962

    06/19/2018, 5:46 AM
    Thanks @gildor! I just started developing a web application in Intellij IDEA, thought of adding coroutines. Got koroutines core.
    g
    • 2
    • 1
  • n

    nikolay

    06/19/2018, 2:37 PM
    Hey! Has anyone else noticed the same problem https://youtrack.jetbrains.com/issue/KT-24980 ?
    d
    i
    • 3
    • 8
  • n

    nick.salerni

    06/19/2018, 4:57 PM
    Hey everyone! Can anyone here give me a list of objective facts that makes Kotlin better than Java? I’m trying to push Kotlin use at work but I keep running into arguments of people saying “but everyone else uses Java, so why not Java?“. I feel like most people are just afraid of change. Has anyone else dealt with similar situations, and if so, how did you deal with it?
    e
    a
    d
    • 4
    • 19
  • m

    Melodeiro

    06/19/2018, 6:40 PM
    Noob question: can i use the common module, from a non-multiplatform code? For example, from Kotlin/jvm. If there is no "expect" classes yet
    b
    • 2
    • 1
  • l

    LeoColman

    06/19/2018, 8:02 PM
    Did you understand why it would be ambiguous to
    addAll(vararg)
    ? I didn't quite see a possible confusion there
    l
    k
    • 3
    • 5
  • j

    Juan Guillermo Gomez - GDG Cali - GDE Firebase

    06/19/2018, 11:20 PM
    My last talk
    s
    • 2
    • 2
  • e

    eygraber

    06/20/2018, 5:09 AM
    Anyone notice any code smells here? I was messing around trying to get an
    unless
    -like operator:
    sealed class Unless {
      object unless : Unless() {
        override val run: Boolean = false
      }
      
      object other : Unless() {
        override val run: Boolean = true
      }
      
      abstract val run: Boolean
    }
    
    inline infix fun Unless.otherwise(block: () -> Unit) {
      if(run) block()
    }
    
    inline fun unless(predicate: Boolean, block: () -> Unit): Unless =
        if(!predicate) {
          block(); Unless.unless
        }
        else {
          Unless.other
        }
    g
    • 2
    • 1
  • o

    o.semen

    06/20/2018, 7:27 AM
    Why Kotlin does not have built in support for binary operations on Byte ? I tried code like this
    val b1: Byte = 2
            val b3: Byte = 7
            val b4 = b1 xor b3
    and IDEA suggested
    import kotlin.experimental.xor
    , but when I tried this:
    val b1: Byte = 2
            val b3: Byte = 7
            val b4 = b1 shl b3
    it does not have even anything to suggest. It is sad as I’m implementing CRC calculation that requires quite a lot of binary operations on bytes an each time I have to cast my bytes…. I do realise that it is possible to write extension. But I’m still wandering why Byte is not treated the same way Int and Long is?
    d
    k
    b
    • 4
    • 8
  • i

    iex

    06/20/2018, 12:47 PM
    @karelpeeters I'm talking about
    fun foo() = print("hello")
    vs.
    fun foo() { print("hello") }
    k
    • 2
    • 6
  • j

    jgodort

    06/20/2018, 12:56 PM
    Hi! I´m wondering if it´s possible create a constructor that throws a exception in some cases? Anyone could tell me how can I achieve this?? Thanks in advance
    r
    • 2
    • 2
  • c

    chirag

    06/20/2018, 1:27 PM
    data class User(
            val name: String? = null,
            val address: String? = null,
            val phone: String? = null
    )
    Suppose I have a data class like above I am validating properties name, address, phone as not null So if its not null how can i change its type to NotNullable because if i use this data class in anywhere else i always have to use !! or ? despite of its already validated for null check. so that data class after validation looks like
    data class User(
            val name: String,
            val address: String,
            val phone: String
    )
    Anybody faced this problem ?
    n
    y
    g
    • 4
    • 5
  • s

    Shawn

    06/20/2018, 3:14 PM
    maybe this’ll end up being a dumb question, but what’s the right approach to take when you have a property you want to assign conditionally based on which constructor you call? the class I’m writing kinda looks like this
    class Foo(val bar, val baz) {
      val doober = mutableMapOf<String, String>()
      val qux: Set<String>
      constructor(bar, baz, lad) : this(bar, baz) {
        // do things to `doober` using `lad`
        qux = doober.keys.toSet()
      }
    }
    more specifically,
    qux
    should be an empty set if the primary constructor is called, and a computed, read-only set if the secondary constructor is called, based on the results of evaluating the parameter unique to it. I tried a separate
    init
    block declared after the secondary constructor to populate the set using the map, but it looks like the init block gets executed before the logic in the body of the secondary constructor. for kicks, I also tried making
    qux
    a constructor parameter, but you can’t call the primary constructor from the secondary one using values you compute in the latter
    e
    • 2
    • 17
  • c

    chattered

    06/20/2018, 4:30 PM
    Think I've found a compiler bug. Is this the place for it?
    g
    • 2
    • 1
  • s

    snowe

    06/21/2018, 1:21 AM
    is there any way to get the second way to work?
    b
    • 2
    • 1
  • r

    rrader

    06/21/2018, 8:41 AM
    after upgrading from 1.2.41 to 1.2.50, when I run only 1 junit method, I get this error
    Error:Kotlin: [Internal Error] java.lang.IllegalStateException: The provided plugin org.jetbrains.kotlin.scripting.compiler.plugin.ScriptingCompilerConfigurationComponentRegistrar is not compatible with this version of compiler
    	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.<init>(KotlinCoreEnvironment.kt:186)
    	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.<init>(KotlinCoreEnvironment.kt:119)
    	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment$Companion.createForProduction(KotlinCoreEnvironment.kt:418)
    	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.createCoreEnvironment(K2JVMCompiler.kt:265)
    	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:154)
    	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:63)
    	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:107)
    	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:51)
    	at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:96)
    	at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$$inlined$ifAlive$lambda$1.invoke(CompileServiceImpl.kt:399)
    	at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$$inlined$ifAlive$lambda$1.invoke(CompileServiceImpl.kt:98)
    	at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:920)
    	at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:98)
    	at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137)
    	at org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:950)
    	at org.jetbrains.kotlin.daemon.CompileServiceImpl.doCompile(CompileServiceImpl.kt:919)
    	at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:397)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:498)
    	at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
    	at sun.rmi.transport.Transport$1.run(Transport.java:200)
    	at sun.rmi.transport.Transport$1.run(Transport.java:197)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    	at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573)
    	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:835)
    	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    	at java.lang.Thread.run(Thread.java:748)
    Caused by: java.lang.AbstractMethodError
    	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.<init>(KotlinCoreEnvironment.kt:184)
    	... 33 more
    s
    • 2
    • 1
  • f

    fabricio

    06/21/2018, 4:17 PM
    I have this function
    fun findProfile(user: UserDocument, vararg fields: String) { ... }
    I'd like to make the vararg parameter required, because if I call that method like
    userService.findProfile(user)
    it doesn't complain. Any idea?
    c
    • 2
    • 1
  • d

    david-wg2

    06/21/2018, 4:30 PM
    how do you usually deal with interoperability when it makes sense for kotlin to return
    String?
    , but it makes sense for java to return
    Optional<String>
    ?
    m
    • 2
    • 1
  • z

    zvozin

    06/21/2018, 8:23 PM
    JS Q: does the JS compiler not support enum methods?
    r
    • 2
    • 1
Powered by Linen
Title
z

zvozin

06/21/2018, 8:23 PM
JS Q: does the JS compiler not support enum methods?
r

robstoll

06/21/2018, 8:30 PM
better ask in #javascript
View count: 1