Consider the following class with a single field:
class MyClass {
@Volatile
var hiddenNumber: Long = 5
fun getNumber(): Long {
return hiddenNumber
}
fun setNumber(newNumber: Long) {
hiddenNumber = newNumber
}
}
Thread A and Thread B have access to one instance of the class.
Thread A assigns a new value to the field of the instance.
instance.setNumber(10)
After this event, Thread B reads the value of the instance using the getter:
val number: Long = instance.getNumber()
What value(s) might Thread B read from number?