When using `lateinit var` on the JVM on a field on...
# announcements
r
When using
lateinit var
on the JVM on a field on an object used from more than one thread do you also need
@Volatile
to prevent other threads seeing it as null, or do you get that for free?
Should have done this before asking… viewing & decompiling the bytecode shows that no, you do not get
@Volatile
for free, so if you want to use a
lateinit var
field in a class that will be used from multiple threads you need to mark it as
@Volatile
manually.