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

    danko9

    06/28/2017, 4:07 PM
    public final T getCellData(final int index) { ObservableValue<T> result = getCellObservableValue(index); return result == null ? null : result.getValue(); } public final T getCellData(final S item) { ObservableValue<T> result = getCellObservableValue(item); return result == null ? null : result.getValue(); }
    s
    r
    d
    • 4
    • 6
  • k

    kirillrakhman

    06/28/2017, 6:08 PM
    val list = mutableListOf<Foo>()
    
    bar(*foo.toTypedArray())
    i
    • 2
    • 6
  • j

    joelpedraza

    06/28/2017, 6:18 PM
    @ilya.gorbunov Is there an open ticket?
    i
    • 2
    • 1
  • e

    enleur

    06/28/2017, 6:39 PM
    if I need a function inside another function I can do it in several ways:
    val isCool = fun(a: Int) = a > 0
    val isCool = { a: Int -> a > 0 }
    fun isCool(a: Int) = a > 0
    are there any differences or pitfalls?
    d
    a
    i
    • 4
    • 4
  • s

    skennedy

    06/28/2017, 7:52 PM
    what does it mean to have a
    private companion object {}
    vs public? i can seem to access everything regardless
    r
    • 2
    • 1
  • o

    orangy

    06/28/2017, 8:05 PM
    But yes, there is an issue, I’ve created a request: https://youtrack.jetbrains.com/issue/KT-18729
    👍 3
    r
    • 2
    • 2
  • k

    karelpeeters

    06/29/2017, 6:45 AM
    @eygraber No, it doesn't matter where you put them anymore, see https://stackoverflow.com/a/38432455
    🎉 1
    👍 1
    d
    • 2
    • 1
  • g

    gildor

    06/29/2017, 10:42 AM
    you can use
    run
    in chain of calls
    r
    • 2
    • 4
  • w

    wilddev

    06/29/2017, 6:28 PM
    What is a shorthand in kotlin for java's code?
    String[][] table = {
    	{"a","b","c"},
    	{"d","e","f"},
    	{"g","h","i"},
    	{"j","k","l"},
    };
    Should I use arrayOf in every line?
    d
    s
    +2
    • 5
    • 4
  • k

    karelpeeters

    06/29/2017, 9:57 PM
    When I add a factory for new values to a MutableMap with "withDefault", get() still returns a nullable reference. Is there a way around this?
    h
    • 2
    • 1
  • e

    eric

    06/30/2017, 2:16 AM
    👍 cool, just making sure. thanks!
    g
    • 2
    • 2
  • k

    kschlesselmann

    06/30/2017, 8:07 AM
    Hi. Since upgrading to 1.1.3 I have the following issue: I have this value object
    @Embeddable
    data class RouterId(val routerId: String) {
    
        init {
            val octets = routerId.split(":")
    
            if (octets.size != 6) {
                throw IllegalArgumentException("$routerId does not consist of 6 octets")
            }
    
            for (octet in octets) {
                Integer.parseInt(octet, 16)
            }
        }
    
        override fun toString(): String {
            return routerId
        }
    }
    which now fails with
    java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.text.StringsKt__StringsKt.split, parameter $receiver
    	at kotlin.text.StringsKt__StringsKt.split(Strings.kt) ~[kotlin-stdlib-1.1.3.jar:1.1.3]
    	at kotlin.text.StringsKt__StringsKt.split$default(Strings.kt:1153) ~[kotlin-stdlib-1.1.3.jar:1.1.3]
    	at domain.model.aircraft.RouterId.<init>(RouterId.kt:9) ~[main/:na]
            ....
    during creation with JPA. In my
    build.gradle
    I use
    plugins {
        id "org.jetbrains.kotlin.jvm" version "1.1.3"
        id "org.jetbrains.kotlin.plugin.noarg" version "1.1.3"
        id "org.jetbrains.kotlin.plugin.jpa" version "1.1.3"
    
        id "org.springframework.boot" version "1.5.4.RELEASE"
    }
    any suggestions? The code runs fine using
    1.1.2
    .
    c
    l
    • 3
    • 15
  • g

    gildor

    06/30/2017, 10:28 AM
    Just override with default value instead set it in
    init
    block
    interface MyInterface {
        var a: String
    }
    
    class ClassA : MyInterface {
        override var a = ""
    }
    k
    • 2
    • 18
  • i

    Ian

    06/30/2017, 4:21 PM
    Got a weird puzzler with receivers. I have a codeblock to which a receiver has been passed. The outer codeblock also has a receiver of the same type. For some reason, when I attempt to call a method on the receiver, it’s calling the outer codeblock’s receiver instead of the inner codeblock’s receiver. I’ve checked in the debugger and $receiver is the correct inner receiver within the inner codeblock, and yet when the method is called the $receiver within it becomes the outer codeblock’s receiver. Hope this makes sense, anyone have any ideas? edit Cleaned up code example and posted to reddit, replies welcome there or here: https://www.reddit.com/r/Kotlin/comments/6kh10d/dsl_receiver_puzzler/
    i
    • 2
    • 2
  • g

    gregd

    06/30/2017, 5:43 PM
    @zak.taccardi You can try to replace
    lateinit
    with
    by lazy { ... }
    if it fits your case
    z
    • 2
    • 2
  • e

    eric

    06/30/2017, 9:23 PM
    According to the spec https://jetbrains.github.io/kotlin-spec/, escape-identifier-character can be “any input-character except backtick.”
    fun `[`() {}
    won’t compile, though. I have found that forward slashes (
    /
    ), backslashes (
    \
    ), open brackets (
    [
    ), and closed brackets (
    ]
    ) are not allowed in backticks. Is this a bug in the documentation, or am I missing something?
    d
    • 2
    • 1
  • n

    napperley

    07/01/2017, 2:51 AM
    Noticed that there is a Webinar scheduled for 13th July on YouTube titled Web Development with Kotlin (webinar is mentioned in the Vaadin newsletter - http://analytics.vaadin.com/vaadin-newsletter-june-july-2017?utm_campaign=Generic%20Newsletter&amp;utm_content=56685817). :kotlin-flag: 🕸️ Would it be possible for the webinar to be mentioned somewhere on the Kotlin website (https://kotlinlang.org/community/talks.html)?
    g
    • 2
    • 5
  • b

    borisdamato

    07/01/2017, 2:36 PM
    Hello, I'm thinking about starting a KUG in my area and since on the KUG listing I see most of the existing groups are on meetup.com I was wondering if JetBrains provides a free meetup.com subscription. Does anyone know?
    o
    • 2
    • 1
  • v

    vkkoshelev

    07/01/2017, 7:41 PM
    Hi guys! I'm trying to build kotlin on win10. I've set jdk paths in the following way: set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_131 set JDK_16=C:\Program Files\Java\jdk1.6.0_45 set JDK_17=C:\Program Files\Java\jdk1.7.0_79 set JDK_18=C:\Program Files\Java\jdk1.8.0_131 However, I've got a compilation error: [kotlinc] Compiling [D:\kotlin\kotlin\compiler\cli\cli-runner\src] => [D:\kotlin\kotlin\dist\classes\runner] [kotlinc] error: no class roots are found in the JDK path: C:\Program Files\Java\jdk1.6.0_45 Can you give me a clue what's wrong with my JDK 1.6?
    i
    • 2
    • 3
  • k

    karelpeeters

    07/02/2017, 6:43 AM
    @dumptruckman Use the elvis operator: replace the entire body of the function with
    = messages[localizablePlugin]?.keys ?: throw IllegalArgumentException(...)
    . See https://kotlinlang.org/docs/reference/null-safety.html for an explanation.
    👍 1
    d
    • 2
    • 1
  • m

    misko

    07/02/2017, 11:40 AM
    Can somebody help me with a coroutines question. I was playing with something like shown in this gist: https://gist.github.com/mvucenovic/65359381a578e37558370cdf4e03ed9e. While running this on i7 with 8 cores, compiled to jvm 1.8 as target, coroutine code defined inside 'async' block was ~10x faster then calling any function doing the same thing inside async block (~700ms vs 8000ms). I know measuring performance with main method is terrible idea, but the difference in execution time is enormous in this gist Can somebody explain to me why is that happening?
    v
    x
    • 3
    • 3
  • k

    karelpeeters

    07/02/2017, 8:38 PM
    This is (probably) going to be fixed in release 1.2! This issue is exactly what we're talking about: https://youtrack.jetbrains.com/issue/KT-14397, and it's marked as a duplicate of https://youtrack.jetbrains.com/issue/KT-7186 (I wouldn't have been able to tell that myself though 🙂 ) which is marked as targeted with major priority for release 1.2.
    🙌 2
    i
    • 2
    • 2
  • a

    amorenew

    07/03/2017, 3:03 AM
    Absolutely avoid calling forEach on Ranges. The cost is extremely high at around 300% https://sites.google.com/a/athaydes.com/renato-athaydes/posts/kotlinshiddencosts-benchmarks
    :trollface: 1
    ✨ 1
    👎 1
    b
    k
    d
    • 4
    • 6
  • h

    harmony

    07/03/2017, 12:09 PM
    are companion objects really that bad?
    k
    • 2
    • 3
  • d

    Dalinar

    07/03/2017, 7:27 PM
    thanks, that's what I was looking for
    a
    • 2
    • 1
  • h

    harmony

    07/03/2017, 10:46 PM
    doubt it can compete
    n
    • 2
    • 2
  • s

    shivthepro

    07/04/2017, 6:47 AM
    Hi I think the (Kotlin Edu) plugin for IntelliJ IDE is not available for the community edition of IntelliJ. Im not able to find the plugin in the repositories. Can someone check on it please https://blog.jetbrains.com/kotlin/2016/03/kotlin-educational-plugin/ .. Please try to make it available. 🙂
    o
    • 2
    • 1
  • g

    gregd

    07/04/2017, 8:18 AM
    Hi all :kotlin:. Does anyone know if there’s any significant performance impact, when importing members of very large classes with a wildcard (e.g.
    io.reactivex.Observable.*
    which is huge) ? I usually try to import members separately. But I see that by default Android Studio switches automatically to
    *
    if there are 2+ imports from the same class
    k
    • 2
    • 3
  • g

    gregd

    07/04/2017, 8:24 AM
    @karelpeeters @gildor How about compile time impact, or something similar?
  • g

    gregd

    07/04/2017, 8:32 AM
    Ok, thanks guys! 🙂 So now I’m curious why did JetBrains change the default wildcard limit from 99+ in Java to 2+ in Kotlin...? 😉
    k
    • 2
    • 2
Powered by Linen
Title
g

gregd

07/04/2017, 8:32 AM
Ok, thanks guys! 🙂 So now I’m curious why did JetBrains change the default wildcard limit from 99+ in Java to 2+ in Kotlin...? 😉
k

karelpeeters

07/04/2017, 8:35 AM
Are you sure the Java default is 99+? I recall it being something below 10 in the past.
g

gregd

07/04/2017, 8:38 AM
At least in the Android Studio I see 99
View count: 2