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

    dalexander

    11/14/2018, 6:53 PM
    I’m running into a weird situation where the properties of my companion object are static rather than being part of the companion itself. They do not have a
    @JvmStatic
    annotation. Anyone have any idea what’s going on? All of the documentation I can find seems to indicate that only the companion object itself should have static. This is causing problems the framework I’m using is trying to use reflection against the local properties and because they are static it’s not working. (This is on 1.3.0 in case it matters)
    d
    • 2
    • 4
  • j

    Jonathan Walsh

    11/14/2018, 11:42 PM
    Does anyone know or have links to Brian Goetz’s opinion on Kotlin?
    i
    • 2
    • 1
  • p

    pavel

    11/15/2018, 12:08 AM
    I have this line of code
    val foo = gitlabEvent.webhookEvent.objectAttributes != null && gitlabEvent.webhookEvent.objectAttributes.action == Action.OPEN
    gitlabEvent
    and
    webhookEvent
    are non-nullable.
    objectAttributes
    is nullable. The compiler is telling me
    Smart cast to 'ObjectAttributes' is impossible, because 'gitlabEvent.webhookEvent.objectAttributes' is a complex expression
    . I thought smart casting was smarter than that 😞
    d
    k
    +2
    • 5
    • 23
  • s

    stevecstian

    11/15/2018, 1:04 AM
    bar
    in
    Fred
    is read-only, but the value returned from getter could be changed from time to time, right?
    k
    • 2
    • 2
  • s

    silas.schwarz

    11/15/2018, 9:23 AM
    hey just a quick question since i'm not to firm with coroutines yet. how would you tackle something that you want to do in parallel (network request) but need to assure that there are never more than 4 requests in parallel (threadpoolexecutor but in coroutines). i've seen that so can assign work to pools (CommonPool) etc but can you create your own pool and define it's parallelism ?! thx 😙
    g
    • 2
    • 12
  • a

    Ana Stu

    11/15/2018, 11:59 AM
    hey! I've developed an Android app in Kotlin with the help of Android Studio, I was thinking in making it available in iOS too, anyone has some experience in this or could tell me and efficient way to do it?
    c
    g
    • 3
    • 3
  • b

    Brian Trezise

    11/15/2018, 1:34 PM
    Hey question: I'm having trouble coding up a spring-data-redis transaction, wondering if anyone can help me out I'm working from an example in Java but the normal ways of converting to Kotlin aren't working: https://docs.spring.io/spring-data/data-redis/docs/current/reference/html/#tx Specifically, here's the java code example:
    -.java
    p
    • 2
    • 5
  • b

    bartvh

    11/15/2018, 2:05 PM
    I'm trying to define an inner type that has one, and exactly one, instance per outer instance (so not an
    object
    ), which cannot be constructed elsewhere without reflection, but I can't seem to get it any tighter than
    inner
    . Making it
    private
    will not allow to me create the one instance:
    inner class TheLock internal constructor()
        private val theLockInstance = TheLock()
    
        inline fun <T> synced(block: (TheLock) -> T) =
                synchronized(this) {
                    block(theLockInstance)
                }
    k
    • 2
    • 2
  • c

    coder82

    11/15/2018, 5:34 PM
    what's the difference of defining: class MyClass(val a:String, val b:String) from class MyClass(a:String, b:String)
    b
    p
    s
    • 4
    • 6
  • c

    Casey Kulm

    11/15/2018, 8:42 PM
    How can I run a main function with the gradle wrapper?
    👍 1
    k
    i
    g
    • 4
    • 6
  • d

    davide

    11/16/2018, 10:49 AM
    Hi all, when I use Kotlin React the render method in RComponent overrides RBuilder.render. More or less I understand why, but I don't find the right documentation about that, also because I don't know how to call this. Where can I found detailed documentation about this technique? Ps: I know that there is a #react channel, but this question, imho, is more related to language :(
    k
    • 2
    • 1
  • m

    muralimohan962

    11/18/2018, 5:05 AM
    The extension functions are just like normal function but they allow you to call them as if they are member functions. Since they can't access class's private or protected members they don't violate open-closed principle.
    👍 3
    a
    • 2
    • 1
  • v

    Venkatesh-Prasad Ranganath

    11/18/2018, 8:13 PM
    Is the Kotlin documentation available at https://kotlinlang.org/docs/reference/ available as a downloadable bundle for offline viewing?
    a
    • 2
    • 2
  • s

    Slackbot

    11/18/2018, 11:17 PM
    This message was deleted.
    k
    • 2
    • 1
  • r

    rnpy

    11/19/2018, 7:00 AM
    anyone has experience with writing annotation processors that generate kotlin code? wondering if there was a way to test compiled code the same way we can test Java with
    compile-testing
    library? (https://github.com/google/compile-testing) currently I'm testing generated sources with a few regex, but that's really not optimal 😕
    u
    • 2
    • 5
  • k

    kitttn

    11/19/2018, 1:01 PM
    hej! Any good way to make a set from List<T> by checking only one property? smth like
    val customersSet = customers.collectToSet { it.phoneNumber }
    which will make a set of customers with non-repeating phone numbers
    m
    r
    • 3
    • 6
  • h

    haroldadmin

    11/19/2018, 4:32 PM
    Hello! I've been stuck trying to wrap my head around coroutines and suspension functions. Suppose I have a suspending function that takes some time to return, and suppose I launch a coroutine on Dispatchers.Main to run that suspending function. To my understanding, what would happen is that when the execution hits the suspension point of the suspending function, instead of blocking the thread to wait for the function to return, the control returns back to the main thread while the function continues executing in the background. Is this correct? If so, which thread is the suspending function now executing on?
    a
    m
    +2
    • 5
    • 21
  • m

    mersan

    11/19/2018, 5:55 PM
    is there a way to create a function to look like this
    doSomething{
      "a"
      "b"
      "c"
    }
    and i can read the input as an list or array of items?
    m
    s
    +3
    • 6
    • 14
  • i

    ImranH

    11/19/2018, 7:37 PM
    Hi, beginner here.
    //wins - horizontal
    fun horizontalWin(letter: String, listIn: listOf<String>() ): boolean {
    var counter = 0
    for (element in listIn ) {
    if (element == letter) {
    counter++
    }
    }
    if (counter == 3) return true
    }
    fun main(args: Array<String>) {
    var row1 = listOf("X","O","_")
    var checkForWin = horizontalWin("X", row1)
    }
    It s a bit rough and I am not sure if it makes sense, but I want to pass a list (or array) in and test it. Thank you.
    s
    r
    a
    • 4
    • 15
  • c

    Casey Kulm

    11/19/2018, 7:40 PM
    I’m trying to use
    readLine()
    to read user input. It is working fine when I run from Android Studio, although when I run from CLI with
    ./gradlew run
    it seems to not be blocking to wait for
    readLine()
    , and is immediately returning
    null
    . Is there something I can do to achieve the expected behavior from CLI?
    d
    • 2
    • 11
  • c

    ClaudiuB

    11/19/2018, 8:51 PM
    I'm trying to compare nullable classes. Has anyone been able to do this? E.g.
    fun isObjectOfSameType(first: Comparable?, second: Comparable?) : Boolean {
                return first::class.java.isAssignableFrom(second)
            }
    however
    javaClass
    or
    ::class.java
    can't be called on
    Nullable
    types
    a
    • 2
    • 2
  • t

    temp_man

    11/19/2018, 8:59 PM
    iterate help
    -.pl
    s
    s
    a
    • 4
    • 22
  • j

    jameskleeh

    11/19/2018, 10:06 PM
    Anyone know how I can get the kotlin version at runtime?
    s
    • 2
    • 2
  • c

    camdenorrb

    11/20/2018, 5:36 AM
    I'm having an issue with restricted suspension, is there a way to bypass it? (Images posted in replies)
    e
    • 2
    • 3
  • e

    edwardwongtl

    11/20/2018, 7:26 AM
    Is there a way to get `enum`’s
    values
    from a instance variable? e.g.
    enum class Kind { Single, Double } 
    class A(val a: Kind)
    
    A().a /// from here get the type of a and get its enum class, then get enum.values?
    r
    d
    • 3
    • 4
  • b

    Bernhard

    11/20/2018, 1:41 PM
    using this function:
    private inline fun <reified T> parseFile(files: Map<String, Path>,
                                             fileName: String,
                                             mapper: ObjectMapper): Array<T> =
        files[fileName]
            ?.toFile()
            ?.readText()
            ?.let {
                mapper.readValue<Array<T>>(it)
            }
            ?: emptyArray()
    • 1
    • 5
  • b

    Bernhard

    11/20/2018, 2:41 PM
    inline private fun <reified T> persistData(data: Iterable<T>) { for (elem in data) }
    a
    • 2
    • 1
  • b

    Bernhard

    11/20/2018, 2:44 PM
    because I'm getting class cast exceptions that LinkedHashMap can not be cast to T
    • 1
    • 2
  • o

    Ovsyannikov Alexey

    11/20/2018, 2:48 PM
    Hello Anybody knows how to call
    suspend
    function from common function in
    common
    module of gradle? I mean that in this module I have no
    runBlocking
    extension
    s
    • 2
    • 1
  • m

    mersan

    11/20/2018, 5:31 PM
    looking in gradle kotlin dsl code
    fun Project.`android`(configure: com.android.build.gradle.LibraryExtension.() -> Unit): Unit =
        extensions.configure("android", configure)
    why the android wrapped in ``?
    r
    v
    • 3
    • 3
Powered by Linen
Title
m

mersan

11/20/2018, 5:31 PM
looking in gradle kotlin dsl code
fun Project.`android`(configure: com.android.build.gradle.LibraryExtension.() -> Unit): Unit =
    extensions.configure("android", configure)
why the android wrapped in ``?
r

Reinis

11/20/2018, 6:33 PM
Is "android" a keyword in language there? If not I think it should work without ``
v

Vladyslav Sitalo

11/20/2018, 6:53 PM
I imagine it’s because it’s auto-generated and “put all the names in `” can be a good default policy there
you can call it without the “`” though
View count: 3