Hey guys, for the sake of studying, I am digging inside the code of the abstract class
LiveData
.
I wonder, why can’t I call
postValue
or
setValue
If I subclass a LiveData?
private val someInstanceOfLiveData = object : LiveData<String>(){}
fun test(){
someInstanceOfLiveData.setValue() // Cannot access 'setValue': it is protected/*protected and package*/ in '<no name provided>'
someInstanceOfLiveData.postValue() // Cannot access 'postValue': it is protected/*protected and package*/ in '<no name provided>'
}
from my understanding,
object : LiveData<String>(){}
is a subclass of the abstract
LiveData
class.
If it is a subclass, why can’t I call
postValue()/setValue()
, which are declared as
protected
inside the
LiveData
?