What a thread can see

Report a typo

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?

Select one or more options from the list
___

Create a free account to access the full topic