https://kotlinlang.org logo
Title
t

tateisu

08/12/2018, 11:40 PM
Is Kotlin's singleton thread-safe?
d

Dominaezzz

08/12/2018, 11:56 PM
Someone correct me if I'm wrong. On the Native and JS backend it doesn't matter. On the JVM backend, it is the same as Java.
t

tateisu

08/12/2018, 11:59 PM
Java does not provide singleton on language level. what do you saying ?
also, Kotlin/Native has worker model, but it uses thread in behind. "it doesn't matter" is not correct.
a

Alexander Levin

08/13/2018, 12:20 AM
According documentation, it is. https://kotlinlang.org/docs/reference/object-declarations.html#object-declarations For JVM (according decompiled version of simple object), it is initialized in static block and static class init is guaranteed to be thread-safe AFAIK
👍 1
d

Dominaezzz

08/13/2018, 12:30 AM
By "it doesn't matter", I meant you can't have shared mutable state. So you do not need to think about Thread-safety.
k

karelpeeters

08/13/2018, 5:48 AM
object MyState { var foo = 4 }