If LiveData<T: Any>’s getter returns T?, but...
# android-architecture
m
If LiveData<T: Any>’s getter returns T?, but the setter only takes T values (non null), and I provide a default value right away (val a = MutableLiveData<String>().apply { value = “” }) - is there any way there the livedata’s value can be null again? Like some under the hood stuff happening? Would be nice it I could call value?.copy() of data class live data without the ? and a default value after that
a
You might want to subclass
MutableLiveData
with a class whose constructor takes a parameter (i.e. the default value) and then overrides the
getValue
function, asserting it's not null
I can't think of any other places where the value would be null
m
Yes my plan was to do exactly that. Thank you 🙂