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

    Ashutosh Panda

    11/19/2019, 4:50 PM
    You will understand whats the problem if you read the snippet it has lamda expression which I am trying to pass a parameter in a function
    s
    m
    • 3
    • 2
  • a

    Animesh Sahu

    11/19/2019, 5:50 PM
    I am having some issues with library https://github.com/uchuhimo/konf in test classes import works fine, while in main intellij says unresolved reference 😞
    implementation "com.uchuhimo:konf:0.20.0"
    c
    • 2
    • 23
  • s

    simtel12

    11/19/2019, 6:32 PM
    Hi people! What's a good channel to join to talk about development of the gradle plugin?
    s
    • 2
    • 2
  • m

    Mikael

    11/19/2019, 6:41 PM
    What is the difference between Kotlin Native and Kotlin Multiplatform?
    a
    s
    • 3
    • 4
  • k

    Kris Wong

    11/19/2019, 8:28 PM
    upgrading to 1.3.60 has broken my project (see #kotlin-native for more on that). so I uninstalled the kotlin plugin and tried installing 1.3.50 from disk. now IDEA can't open any of my projects.
    d
    • 2
    • 4
  • b

    Ben Piatt

    11/19/2019, 9:21 PM
    How do I pass a value of a non-null type to a method that accepts that type but as a nullable parameter? The other way around makes sense to safe-check, but if I'm giving you a non-nullable type as a parameter and you can accept nullable types, there's gotta be a way it can be taken
    s
    k
    • 3
    • 17
  • e

    E.Kisaragi

    11/20/2019, 3:17 AM
    Is there a way to create static extension function to existing class?
    r
    x
    +3
    • 6
    • 6
  • l

    Lulu

    11/20/2019, 5:36 AM
    Why the std-lib doesn't have a map implementation written in Kotlin, and instead uses platform-specific ones with expect/actual? Is performance the reason?
    b
    e
    +3
    • 6
    • 6
  • v

    Viktor Qvarfordt

    11/20/2019, 10:02 AM
    Am I not using higher-ordered-functions properly or is Kotlin’s type inference limited? (This is a silly example where I’m trying to get a “flow” or “left compose” operator - I know this is most natural with dot chaining in Kotlin.)
    j
    k
    • 3
    • 13
  • f

    Fudge

    11/20/2019, 11:09 AM
    What is the relative performance of a `lateinit var`'s
    isInitialized
    ? Is it just checking some flag, or is it some expensive reflective operation, maybe it allocates objects?
    d
    p
    +2
    • 5
    • 10
  • l

    LeoColman

    11/20/2019, 4:14 PM
    Hey guys! What's your usual take on having more than one class in the same file? I want to extract a piece of code from a complex class to a less-complex class and call it another service. However, this class will only be used by the class I'm extracting, and I don't really want to pollute the package namespace with a class that's not useful anywhere else. Should I keep it inside the same file?
    :yes: 9
    m
    p
    +4
    • 7
    • 12
  • r

    ryn1x

    11/20/2019, 4:49 PM
    How can I perform an action on a SimpleBooleanProperty change only once? Something like:
    isConnected.onChange {
        timer.scheduleAtFixedRate(timerTask, 0, period)
        // unsubscsibe
    }
    , where isConnected is a SimpleBooleanProperty
    • 1
    • 1
  • m

    Marko Mitic

    11/20/2019, 5:36 PM
    Constructor executes before
    private var mGlucoseState = GlucoseState.NONE
    line
    p
    • 2
    • 1
  • h

    Hullaballoonatic

    11/20/2019, 6:35 PM
    How can I be sure that casting is safe? Would the following be a completely safe cast, and thus not require a conversion function?
    class Foo(vararg values: Int) : List<Int> by values.toList() {
        fun bar() = "foobar"
    }
    
    (listOf(1, 2, 3) as Foo).bar()
    Casting is cheaper than conversion, because it doesn't require instantiating a new object, right?
    m
    • 2
    • 3
  • h

    Hullaballoonatic

    11/20/2019, 11:34 PM
    Does the compiler optimize the following code so that the return value is not computed with every
    toString
    given that it never changes, or should I create a backing field?
    class Foo(val str: String) {
        override fun toString() = str.reversed()
            .repeat(1000)
            .trim()
            .otherStuff()
    }
    d
    s
    • 3
    • 3
  • k

    Ky Leggiero

    11/20/2019, 11:57 PM
    I hate how clumsy IDEA and Android Studio are. All I did was create a new project called "Ben Leggiero's Résumé" and first it hits me with confusion over the apostrophe, and then this:
    com.android.tools.idea.gradle.project.sync.ng.NewGradleSyncNotSupportedException: New Gradle Sync is not supported due to containing Kotlin modules
    ➕ 2
    d
    • 2
    • 8
  • d

    Daniele Segato

    11/21/2019, 7:06 AM
    Using java code i can use interface with a single method just by using the interface name, like this:
    val x = SomeInterface { }
    Thanks to SAM. However when i try the same thing on kotlin interface I'm forced to create an anonymous class:
    val x = object : SomeInterface {
      fun someMethod() { }
    }
    If i instead create a type alias for it I can write it without the object ceremony but I've no way of specifying what it is:
    typealias SomeInterface = (): Unit
    
    // ...
    
    val x = { }
    Yes i know i can do
    val x: SomeInterface = { }
    But picture this situation:
    val x: SomeInterface = when (foo) {
      "A" -> { { } }
      "B" -> { { } }
    }
    I need double
    {
    , which is horrible. I think it would be much better to be able to write;
    val x = when (foo) {
      "A" -> SomeInterface { }
      "B" -> SomeInterface { }
    }
    Is there a way to do this or a way to improve the previous example?
    b
    h
    • 3
    • 7
  • j

    Johan Luttu

    11/21/2019, 10:41 AM
    Why does Kotlin 1.3.60 push a constant 0 to the operand stack and then store it away before printing?
    fun hello() {
        println("hello")
    }
    Bytecode:
    public static final void hello();
        Code:
           0: ldc           #7                  // String hello
           2: astore_0
           3: iconst_0
           4: istore_1
           5: getstatic     #13                 // Field java/lang/System.out:Ljava/io/PrintStream;
           8: aload_0
           9: invokevirtual #19                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
          12: return
    s
    m
    a
    • 4
    • 4
  • s

    sikri

    11/21/2019, 12:42 PM
    https://kotlinlang.org/ Probably a bug
    i
    • 2
    • 1
  • b

    Blundell

    11/21/2019, 1:37 PM
    General question about experimental features, if anyone knows please. https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-test/kotlinx.coroutines.test/-test-coroutine-dispatcher/index.html Shows this as experimental. (In 1.3.2, which i think is the latest). Is there anyway to know in what version / when / if it'll stop being experimental? (for example with the Android Gradle Plugin they have alpha's where you know once that alpha goes stable channel)
    👍 1
    a
    • 2
    • 2
  • j

    Jamie Taylor

    11/21/2019, 4:18 PM
    Does anyone know why map on arrays returns a list and not an array?
    d
    s
    m
    • 4
    • 5
  • m

    Matthias R

    11/21/2019, 5:01 PM
    Hey guys, I am basically doing a post request with ktor httpClient and I get back a HttpResponse successfully. With that I can see the response status and headers but I cannot see the body. How can I find the body?
    l
    e
    a
    • 4
    • 5
  • t

    trevjones

    11/21/2019, 6:05 PM
    a.mapIndexed { index, value -> value to myList[index] }.toMap()
    ?
    h
    k
    +2
    • 5
    • 47
  • a

    alex

    11/21/2019, 7:26 PM
    Can you get an instance of
    Class
    object for top-level declaration, e.g.:
    val x = ???::class.java.getResourceAsStream(...)
    ?
    🇳🇴 1
    k
    • 2
    • 1
  • t

    tipsy

    11/21/2019, 7:45 PM
    does anyone know how to capture a junit assertionerror that happens in a different thread? 🤔
    f
    • 2
    • 4
  • r

    ronnie173

    11/21/2019, 8:02 PM
    Anybody know how to get a context in a regular unit test? Not an integration test.
    r
    c
    • 3
    • 4
  • r

    rustyrazorblade

    11/21/2019, 9:33 PM
    Hey folks. Trying to figure out why accessing the
    keyvalue
    val inside this object is a problem:
    class Tables(val session: Session) {   
       val queries = object {
            val keyvalue = object {
                val insert = prepare("INSERT INTO keyvalue (id, value) values (?, ?)")
                val select = prepare("SELECT * from keyvalue WHERE id = ?")
            }
            val timeseries = object {
                val insert = prepare("INSERT INTO timeseries (id, c, data) values (?, ?, ?)")
                val selectPartition = prepare("SELECT * from timeseries WHERE id = ?")
                val selectPartitionReverse = prepare("SELECT * from timeseries WHERE id = ? order by c DESC")
            }
        }
    }
    I’m not able to do essentially this:
    tables = Tables(session)
    tables.queries.keyvalue
    anyone know why?
    s
    m
    • 3
    • 7
  • a

    Andy Gibel

    11/21/2019, 9:47 PM
    For the Kotlin KEEP process https://github.com/Kotlin/KEEP/ - does anyone know why discussions are meant to be broken up into an ISSUE istead of directly in a PR? I also see some discussion in the PR. Also, is the idea that if an idea is agreed upon after discussion in the issue the issue is closed and the PR is merged?
    g
    • 2
    • 2
  • j

    John

    11/21/2019, 10:11 PM
    Is there any data on which spaces is kotlin most used on? I.e. Android, rest services, web clients, etc
    r
    • 2
    • 1
  • j

    John

    11/21/2019, 10:12 PM
    And followed by Android
    n
    r
    • 3
    • 2
Powered by Linen
Title
j

John

11/21/2019, 10:12 PM
And followed by Android
n

nfrankel

11/21/2019, 10:16 PM
i’m afraid it’s android first and foremost and followed much much later by back-end
r

Ruckus

11/21/2019, 10:57 PM
Android is definitely the most common, but not by that much according to JetBrains. About 2/3 of Kotlin users are targeting Android, and over half target other JVMs.
View count: 1