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

    GauthierPLM

    12/14/2017, 8:42 AM
    Is there any simple profiler for Kotlin? I’m writing an algo and would like to know which part take the most of time
    l
    y
    • 3
    • 2
  • l

    lovis

    12/14/2017, 8:50 AM
    Am I being stupid just now, or is the only way of properly annotating a constructor-defined property like this:
    class CreateUserDTO(
            @Email @get:Email @setparam:Email
            var email: String
    )
    ? I mean, isnt't there a way to combine these things? When I annotate the constructor param, I usually also want to annotate the getter and setter, right?
    y
    q
    • 3
    • 7
  • d

    diesieben07

    12/14/2017, 10:08 AM
    I need to call a Java method with a varargs parameter and the API requires me to pass
    null
    for the "vararg array". Is there a way to do that in Kotlin?
    null as Array<String>?
    does not work.
    k
    • 2
    • 2
  • j

    jstuyts-squins

    12/14/2017, 10:09 AM
    Not with a map, why don't you create a (data) class with fields instead?
    class RequiredData(val firstField: String, val secondField: String)
    
    interface SomeDataProvider {
        fun provide(): RequiredData
    }
    h
    • 2
    • 1
  • k

    kartikpatodi

    12/14/2017, 10:37 AM
    Hello, can anyone tell me how can we create a helper function for a Java static method so that we can avoid the class names on every method call eg.
    Assertions.assertThat()
    can be called like
    someFun()
    is it possible?
    k
    d
    • 3
    • 9
  • d

    damian

    12/14/2017, 3:20 PM
    @Andreas Sinz using
    when
    on an instance of
    SpecificExceptions
    the auto-completion for all branches at least doesn’t work
    a
    • 2
    • 11
  • k

    karelpeeters

    12/14/2017, 4:43 PM
    Does a tool similar to the Kotlin-JS DCE exist for the JDK? I'm making a fat jar that has to include the whole Kotlin runtime, is there a way to strip that down?
    a
    • 2
    • 2
  • a

    anstaendig

    12/14/2017, 4:58 PM
    How do I put a url into KDoC ?
    k
    • 2
    • 3
  • c

    chansek

    12/14/2017, 5:39 PM
    Just updated kotlin version to 1.2.10 and restarted Android Studio I got below errors Cannot load facet kotlin Plugin supporting feature Facet[kotlin-language] is disabled So tried to enable it by going to Plugin settings and after restarting it is getting disabled again.
    k
    • 2
    • 6
  • e

    eygraber

    12/14/2017, 9:00 PM
    Anyone here run into this issue while updating to 1.2.10? Kinda nervous to update now - https://discuss.kotlinlang.org/t/kotlin-1-2-10-introduces-weird-android-sdk-requirement/5809
    k
    • 2
    • 1
  • r

    rrader

    12/15/2017, 8:23 AM
    https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib/common/src/kotlin why all file names has "H" suffix?
    g
    m
    • 3
    • 10
  • r

    rrader

    12/15/2017, 8:39 AM
    according to https://github.com/yole/kotlin-style-guide/issues/6
    object
    should extend a base class or implement an interface, can please someone show real use case when we need on object that extend a base class or implement an interface?
    g
    • 2
    • 1
  • j

    jstuyts-squins

    12/15/2017, 9:01 AM
    @rrader It is useful for implementations of base classes or interfaces that do not have any state. You can use these objects as
    null
    objects in a lot of cases. For example:
    object NoOperationMouseListener : MouseListener {
        ...
    }
    The mouse listener member of your class does not have to be nullable in this case:
    class MouseEventEmittingClass {
        var mouseListener: MouseListener = NoOperationMouseListener
    }
    r
    • 2
    • 2
  • n

    natpryce

    12/15/2017, 9:55 AM
    Hey JetBrains folks… would it be possible to put the latest version number of Kotlin somewhere more visible on the Kotlin web site, where it can be seen without scrolling?
    👍🏽 1
    ➕ 1
    m
    o
    c
    • 4
    • 4
  • m

    mc

    12/15/2017, 1:24 PM
    Do you consider using
    java.util.Optional
    in kotlin to be idiomatic (given the built-in nullable types feature)?
    c
    a
    +4
    • 7
    • 7
  • r

    rrader

    12/15/2017, 1:43 PM
    https://twitter.com/SalesforceDevs/status/921081025576554501 Kotlin logo?
    k
    • 2
    • 1
  • j

    jw

    12/15/2017, 5:22 PM
    filter doesn't change the type, it only removes elements
    j
    a
    • 3
    • 5
  • a

    Andreas Sinz

    12/15/2017, 5:28 PM
    use
    filterNotNull()
    j
    k
    • 3
    • 3
  • o

    orangy

    12/15/2017, 5:35 PM
    May be not store nulls in a map in the first place? 🙂
    ➕ 5
    j
    • 2
    • 2
  • c

    czyzby

    12/15/2017, 8:05 PM
    Is it possible to implement a fully functional Kotlin kernel for Jupyter with the current tools? I think there are two separate projects trying to achieve that, but both lack pretty basic features like auto-completion.
    • 1
    • 1
  • c

    christophsturm

    12/15/2017, 8:30 PM
    what do people use to consume rest webservices with kotlin? retrofit?
    ➕ 2
    r
    • 2
    • 1
  • k

    kevinmost

    12/15/2017, 9:00 PM
    Foo::myMember.annotations
    b
    • 2
    • 1
  • j

    jtonic

    12/15/2017, 9:54 PM
    Is this an issue? Below the session “field” is found when isAbstract is called on it but throws a strange error when isInitialized is called. class Session { companion object INSTANCE { private lateinit var session: Session fun createSession() = Session().apply { session = this } fun weird() { Session.INSTANCE::session.isAbstract // this works!!!! Session.INSTANCE::session.isInitialized // but this doesn’t! java.lang.NoSuchFieldError: session thrown at runtime. } } } There is any explanation about this? Thank you.
    o
    • 2
    • 3
  • t

    tipsy

    12/16/2017, 11:18 AM
    /**
     * Returns the first element yielding the largest value of the given function or `null` if there are no elements.
     */
    public inline fun <T, R : Comparable<R>> Iterable<T>.maxBy(selector: (T) -> R): T? {
    c
    • 2
    • 1
  • k

    karelpeeters

    12/16/2017, 8:11 PM
    Unit
    is not like
    void
    at all, it's just an ordinary singleton object.
    y
    • 2
    • 7
  • k

    Kris

    12/16/2017, 9:03 PM
    Hello, tried googling without much luck, but does anyone have any kind of estimation on when native will be "ready"? I have a project starting early next year which is an app on iOS, android and windows phone, and would love to use kotlin for it
    g
    • 2
    • 1
  • s

    shamrock_frost

    12/17/2017, 3:42 AM
    Is there a reason Kotlin doesn't have nested destructuring or destructuring in
    is
    clauses of a
    when(x)
    statement?
    a
    r
    • 3
    • 2
  • s

    Shawn

    12/17/2017, 5:38 AM
    @qwert_ukg not really sure what you mean - how do you plan on using companion objects?
    q
    • 2
    • 5
  • j

    jtonic

    12/17/2017, 2:21 PM
    Hi, Frankly I don’t see the benefit of const taken into account only primitives and String type are allowed. Can someone shed a light why there is such constraint on const ? Many times I started with a const which complied with the restriction, and then when I try to type migration refactor, say, a String type constant to a specific type I end up getting a compilation error. See an example below. And then I have to come up with another thing, which requires a significant refactor, and all this just because of this restriction. Is this related to constant expression in java language?
    class A {
        companion object {
            const val name1 = "Antonel"
            const val name2 = StringBuilder("Antonel")
        }
    }
    error: const 'val' has type 'kotlin.text.StringBuilder /* = java.lang.StringBuilder */'. Only primitives and String are allowed
    Antonel.
    r
    s
    a
    • 4
    • 7
  • c

    czyzby

    12/17/2017, 4:35 PM
    I'm still getting an internal compiler error on inline method after updating to Kotlin 1.2.10. Is this a known issue?
    org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: Couldn't inline method call 'addTooltip' into
    @org.junit.Test public final fun `should add Tooltip with init block`(): kotlin.Unit defined in ktx.scene2d.TooltipFactoriesTest
    
    (...)
    
    Cause: addTooltip$default (Lcom/badlogic/gdx/scenes/scene2d/Actor;Ljava/lang/String;Lcom/badlogic/gdx/scenes/scene2d/ui/Skin;Lcom/badlogic/gdx/scenes/scene2d/ui/TooltipManager;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lcom/badlogic/gdx/scenes/scene2d/ui/Tooltip;:
      @Lorg/jetbrains/annotations/NotNull;() // invisible
    
    (...)
    
    The root cause was thrown at: SMAPAndMethodNode.kt:38
    	at org.jetbrains.kotlin.codegen.inline.InlineCodegen.throwCompilationException(InlineCodegen.kt:132)
    :kotlin: 1
    l
    i
    • 3
    • 9
Powered by Linen
Title
c

czyzby

12/17/2017, 4:35 PM
I'm still getting an internal compiler error on inline method after updating to Kotlin 1.2.10. Is this a known issue?
org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: Couldn't inline method call 'addTooltip' into
@org.junit.Test public final fun `should add Tooltip with init block`(): kotlin.Unit defined in ktx.scene2d.TooltipFactoriesTest

(...)

Cause: addTooltip$default (Lcom/badlogic/gdx/scenes/scene2d/Actor;Ljava/lang/String;Lcom/badlogic/gdx/scenes/scene2d/ui/Skin;Lcom/badlogic/gdx/scenes/scene2d/ui/TooltipManager;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lcom/badlogic/gdx/scenes/scene2d/ui/Tooltip;:
  @Lorg/jetbrains/annotations/NotNull;() // invisible

(...)

The root cause was thrown at: SMAPAndMethodNode.kt:38
	at org.jetbrains.kotlin.codegen.inline.InlineCodegen.throwCompilationException(InlineCodegen.kt:132)
:kotlin: 1
l

louiscad

12/17/2017, 8:31 PM
@czyzby Are you using inline lambdas default values feature?
c

czyzby

12/17/2017, 8:49 PM
Yes. Without the
inline
keyword, the function works as expected.
l

louiscad

12/17/2017, 9:19 PM
So I already reported a similar error. Will make it public and will share you the link later
@czyzby See my issue here: https://youtrack.jetbrains.com/issue/KT-21827
Please, add a comment for your use case in the :youtrack: issue
i

ilya.gorbunov

12/18/2017, 3:33 AM
@czyzby What was the version of Kotlin before you have upgraded to 1.2.10?
c

czyzby

12/18/2017, 7:15 AM
It did not work in 1.2.0 as well. Adding default funtional parameters to an inline method broke it, I temporarily converted it to a non-inlined function. Without the default functional parameter, it worked as expected.
@ilya.gorbunov
l

louiscad

12/18/2017, 8:37 AM
@ilya.gorbunov In my similar case, I got the issue on both 1.20 and 1.2.10
View count: 5