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

    Marko Mitic

    08/05/2019, 7:03 PM
    How to avoid ConcurrentModificationException in concurrent code when iterating Map's values? Any safe API for this?
    l
    b
    +1
    6 replies · 4 participants
  • m

    Michael

    08/05/2019, 8:28 PM
    what’s the best practices way to reference a class’s field dynamically by name? Use reflection?
    d
    j
    10 replies · 3 participants
  • v

    vitus

    08/05/2019, 8:56 PM
    Hi people! The CTO of our company is trying to convince our Android team to start prefixing all class names with a three letter uppercase abbreviation of the company’s name. E.g. Company name: Fancy Coffee Roasting Class name: FCRProfileViewModel He’s also an iOS developer, where prefixing seems more reasonable because of the global namespace pollution and conflicts that are caused by not requiring imports, if I’m not mistaken. It also seems more natural as it appears to be some legacy of Objective-C. Apart from the arguments of additional noise that comes with the three uppercase letters and that this pattern is quite uncommon for Kotlin, what would be your arguments against it? We’re also worried that this change will break some of the beauty our IDE supplies, like suggesting names, as variable names aren’t meant to include the prefix.
    🔥 1
    😂 13
    😨 1
    🤦‍♂️ 10
    j
    h
    +12
    25 replies · 15 participants
  • a

    Animesh Sahu

    08/06/2019, 4:29 AM
    Hello people! I am having some troubles creating a thread pool. First of all, reference to projects for which i'm having problem: 1. https://github.com/Animeshz/threadpool (isn't completed yet, i.e. problem is in here) 2. https://github.com/Animeshz/promise (dependency, don't think so there's problem here but maybe co-related) the problem is that the code in the done block isn't executing always (like it executes sometime whereas sometime isn't). https://github.com/Animeshz/threadpool/blob/master/src/test/kotlin/com/animeshz/threadpool/PoolTest.kt#L14 Summary what is going on: 1. While when in creating the pool itself i registered a shutdown hook which prevent the jvm to exit before all tasks have been executed, https://github.com/Animeshz/threadpool/blob/master/src/main/kotlin/com/animeshz/threadpool/Pool.kt#L41 2. And shutdown hook calls join function in the pool which blocks the jvm calling .join() on all the worker threads. And also starts a periodic timer which checks for the worker threads being completed by checking currentlyBusy property on the worker(that i'll explain in point 3) and kills which are not busy. https://github.com/Animeshz/threadpool/blob/master/src/main/kotlin/com/animeshz/threadpool/Pool.kt#L53 3. Worker threads transition their currentlyBusy state by if check when queue(stack) is empty, and "that should only happens if the promise is done executing all the handlers"(but done is not getting executed sometime) , and loops back to stack.dequeue(), and that blocks the thread by an ReentrantLock and since periodic timer in last point i mentioned, interrupts the thread when currentlyBusy property gets false. https://github.com/Animeshz/threadpool/blob/master/src/main/kotlin/com/animeshz/threadpool/Worker.kt#L53 I'm really unable to catch why is that done() block is not executing
    k
    3 replies · 2 participants
  • a

    Antanas A.

    08/06/2019, 9:08 AM
    Hello, is it possible to have by lazy property which calls suspend function for a value? Eg
    val context by lazy { contextProvider() }
    where contextProvider() is suspend function
    d
    g
    +2
    86 replies · 5 participants
  • o

    Onur

    08/06/2019, 2:37 PM
    Can I make
    xPath
    and
    contextString
    private?
    d
    r
    +1
    4 replies · 4 participants
  • m

    Max Spencer

    08/06/2019, 3:47 PM
    Hey there, I wonder if anyone here can help me. I am doing some work with Kotlin Multiplatform and am running into this kind of exception:
    kotlin.native.IncorrectDereferenceException: Trying to access top level value not marked as @ThreadLocal or @SharedImmutable from non-main thread
    The context is quite convoluted and I'm not sure if it is relevant or not. I can elaborate further if anyone thinks it might help, but briefly: I've created a Kotlin Multiplatform library (see https://github.com/guardian/multiplatform-ophan) which can send various "events" to an analytics service called "Ophan". I've come up with a way to implement "Native Modules" for React Native applications using shared Kotlin Multiplatform code (see https://github.com/guardian/react-native-with-kotlin) Now I'm trying to put these two ideas together. But unfortunately, although the
    multiplatform-ophan
    library works as expected when consumed directly from Android or iOS, I run into the above exception on iOS when it is included in a React Native app via this extra layer of indirection. I don't expect anyone to help me debug this issue if it's anything to do with React Native and I appreciate you might think this seems like a very odd combination of things to be doing. But even just some general pointers about the kind of pitfalls you might expect in this area would be greatly appreciated.
    1 reply · 1 participant
  • l

    Luis Munoz

    08/06/2019, 4:43 PM
    Anyone know why I am getting the following error and how to fix it?
    Untitled
    k
    3 replies · 2 participants
  • n

    Nezteb

    08/06/2019, 6:18 PM
    So these are the definitions of the 5 kotlin scoping functions
    inline fun <T, R> with(receiver: T, block: T.() -> R): R {
        return receiver.block()
    }
    inline fun <T> T.also(block: (T) -> Unit): T {
        block(this)
        return this
    }
    inline fun <T> T.apply(block: T.() -> Unit): T {
        block()
        return this
    }
    inline fun <T, R> T.let(block: (T) -> R): R {
        return block(this)
    }
    inline fun <T, R> T.run(block: T.() -> R): R {
        return block()
    }
    What does the
    T.() -> R
    imply? I know
    (T) -> R
    is a function that takes a
    T
    and returns an
    R
    , but what does
    T.()
    mean?
    👍 1
    l
    a
    +4
    10 replies · 7 participants
  • a

    Ankur Gupta

    08/07/2019, 4:31 AM
    I have a code which looks like this
    class TeaMaker {
        private lateinit var tea: Tea
    
        fun prepareTea() {
            tea = Tea()
        }
    
        fun addSugar() {
            tea.add(Sugar())
        }
    }
    
    class Restaurant {
        ...
        //In some method
        val teaMaker = TeaMaker()
    
        teaMaker.prepareTea()
        teaMaker.addSugar()
    }
    The problem is when i call addSugar I get the lateinit not initialized exception. I tried setting up debugger but found it is initialised. Am I missing something?
    a
    d
    +1
    10 replies · 4 participants
  • v

    Vishal

    08/07/2019, 5:42 AM
    I'm new to kotlin, and created a sample Multiplatform application(common code will be shared between Android and IOS) using https://kotlinlang.org/docs/tutorials/native/mpp-ios-android.html#creating-an-android-project reference. Everything is working fine except
    bin
    folder is not getting generated in
    SharedCode/build
    folder
    b
    3 replies · 2 participants
  • t

    Tsvetozar Bonev

    08/07/2019, 10:38 AM
    How would a higher-order function in a companion object variable act when being called by multiple threads? Will Kotlin run the function in the caller thread or are objects somehow shared across threads? I need a provided for a thread's namespace and it would be much cleaner to have that provider be a higher-order companion object function but I'm unsure whether it will correctly call the provider from the thread
    d
    r
    6 replies · 3 participants
  • s

    Slackbot

    08/07/2019, 2:35 PM
    This message was deleted.
    c
    a
    +2
    9 replies · 5 participants
  • f

    Felipe Tavares

    08/07/2019, 2:50 PM
    Guys... I'm with a problem with ktlint... When I execute, returns me this message:
    Process 'command '/usr/lib/jvm/java-11-openjdk-amd64/bin/java'' finished with non-zero exit value 1
    Can someone help me please?
    m
    2 replies · 2 participants
  • w

    wathek

    08/07/2019, 5:07 PM
    Hi wonderful people, I'm wondering what's the difference between those two lines of code:
    // First method
    val test = Mono.just("hello").run { block() }
    
    // Second method
    val test = Mono.just("hello").block()
    Both cases
    test
    has
    String?
    type
    k
    w
    18 replies · 3 participants
  • j

    Jon

    08/07/2019, 11:14 PM
    is there a way to create an extension function for an annotated data class?
    k
    s
    +2
    12 replies · 5 participants
  • j

    jermainedilao

    08/08/2019, 7:51 AM
    Hi, I have a basic question. Can you hand me a link that explains the data type hierarchy when declaring a variable? Lets say I have:
    val list = mutableListOf<String>()
    variable
    list
    will be a mutable list. but if I have
    val list: List<String> = mutableListOf<String>()
    variable
    list
    will be an immutable list. Can someone explain the hierarchy here? Is the defined variable data type always becomes the winning data type?
    d
    t
    +2
    11 replies · 5 participants
  • b

    bhavin

    08/08/2019, 9:01 AM
    How to compare Any type arraylist
    var getVideoList: ArrayList<Any>
    look at this my code https://paste.ofcode.org/PpCQuDjkAvtKpv7U29k7cD
    d
    g
    20 replies · 3 participants
  • l

    Luis Munoz

    08/08/2019, 3:48 PM
    How do I get this to work?
    data class with different data type example
    s
    7 replies · 2 participants
  • a

    Adam Spofford

    08/08/2019, 5:16 PM
    and I've had no response in like a month so I was hoping someone here might know something
    s
    14 replies · 2 participants
  • h

    Harsh Deshpande

    08/08/2019, 5:23 PM
    Hello - i'm new to the channel, but I wanted to know if anyone has used the new Kotlin Native debugging plugin for 1.3.50-eap-54 (link: https://plugins.jetbrains.com/plugin/12775-native-debug-for-intellij/) - using Idea Ultimate, I have successfully imported and enabled the plugin, updated kotlin to 1.3.50-eap-54, and set the update channel to early access 1.3.x, but even with this, my code does not seem to stop at breakpoints in my native code. Is anyone having similar issues or know how to get around it?
    s
    3 replies · 2 participants
  • s

    spierce7

    08/08/2019, 5:25 PM
    How do I use an extension function that's nested in an object from outside that object? i.e.
    object Example {
        fun String.exampleExtension() {
        }
    }
    
    fun test(str: String) {
        str.exampleExtension() // Doesn't work. How can I use the extension function?
    }
    s
    5 replies · 2 participants
  • g

    Gunslingor

    08/08/2019, 7:05 PM
    Okay so... I'm developing with Angular CLI now on my web front end, but my backend uses SpringBoot with Kotlin.... seems so incredibly silly to write one part of the app in kotlin and the other part in typescript... is there ever going to be a Kotlin based Angular CLI or is Typescript going to maintain it's monopoly on that platform?
    s
    j
    +3
    11 replies · 6 participants
  • m

    Mike R

    08/09/2019, 2:50 AM
    What is the state of native code compilation for Kotlin? My team at work is needing a compiled language without many dependencies and it is Kotlin vs Golang. The ability to compile kotlin to native code is appealing, but someone on my team said they had issues with building a binary for Windows?
    j
    m
    +2
    7 replies · 5 participants
  • n

    Nikky

    08/09/2019, 5:11 AM
    is
    val nullable = platformTypeVariable ?: null
    the correct way to tell Kotlin that a platform type is nullable ?
    a
    1 reply · 2 participants
  • s

    Slackbot

    08/09/2019, 2:03 PM
    This message was deleted.
    a
    t
    2 replies · 3 participants
  • s

    sdeleuze

    08/09/2019, 2:52 PM
    I am trying to get some info about a pretty annoying Java interrop issue (existing issue for example). Does that ring a bell to anyone? It happens with or without the new type inference. https://kotlinlang.slack.com/archives/C0B8ZTWE4/p1565359547058200
    c
    5 replies · 2 participants
  • n

    Nezteb

    08/09/2019, 4:32 PM
    So I end up using https://github.com/GoogleChrome/puppeteer a lot for browser automation, but it requires JS. Is there a Kotlin alternative? I’d rather avoid Selenium if I can. Are there any fancy modern libraries for browser automation in Kotlin?
    j
    t
    7 replies · 3 participants
  • j

    Jon

    08/09/2019, 10:31 PM
    What would be the idiomatic way to do this in Kotlin? I am doing a switch on a String that has well defined values. I'd like to make sure that all these values are handled in the switch statement. I do this in several locations. In other languages, I would have created a function that converts string to some type and then switch on that type. In the "default" section of the switch statement I would have thrown some assertion to make sure all cases are handled.
    k
    m
    8 replies · 3 participants
  • a

    asad.awadia

    08/10/2019, 12:37 AM
    Theoretical question: A simple kotlin jar ran on a server untouched - how long can it hypothetically run before it crashes/exceptions? Or is the jvm mature enough that it won’t? Sort of like nginx that almost never crashes and is always chugging along
    j
    1 reply · 2 participants
Powered by Linen
Title
a

asad.awadia

08/10/2019, 12:37 AM
Theoretical question: A simple kotlin jar ran on a server untouched - how long can it hypothetically run before it crashes/exceptions? Or is the jvm mature enough that it won’t? Sort of like nginx that almost never crashes and is always chugging along
j

jw

08/10/2019, 1:00 AM
suspend fun main() = suspendCoroutine { }
will run forever and never crash unless it's due to outside factors
👍 1
View count: 4