https://kotlinlang.org logo
m

maxmello

08/29/2018, 12:47 PM
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

alexsullivan114

08/30/2018, 5:41 PM
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

maxmello

08/31/2018, 9:39 AM
Yes my plan was to do exactly that. Thank you 🙂