https://kotlinlang.org logo
#android
Title
# android
m

myanmarking

10/04/2017, 10:30 AM
idk the kotlin way =(
g

gildor

10/04/2017, 10:32 AM
Maybe something like:
Copy code
@get:Synchronized
@set:Synchronized
var autoStartService = false
m

myanmarking

10/04/2017, 10:32 AM
wat i tought at first, but i always heard its bad idea to syncronize a bool 😛
does my way work as well ?
e

ebonet

10/04/2017, 10:34 AM
You can use AtomicBoolean as well, instead of synchronizing a boolean
m

myanmarking

10/04/2017, 10:35 AM
cool 😛 that might work
my lock works as well right? (appart from not being ideal)
g

gildor

10/05/2017, 2:44 AM
Yes, AtomicBoolean probably good idea. But I don’t think that it’s bad in this case, because you don’t syncronize boolean value itself, only setters and getters. Also,
@set:Syncronized + @field:Volatile
should work, but actually AtomicBoolean is better
3 Views