william
06/16/2020, 1:54 AMimport androidx.lifecycle.MutableLiveData
class ClearableLiveData<T> : MutableLiveData<Clearable<T>>() {
fun clear(t: T) {
super.postValue(Clearable.Clear)
super.postValue(Clearable.Value(t))
}
}
sealed class Clearable<T> {
object Clear: Clearable<Any>()
data class Value<T>(val t: T): Clearable<T>()
}
The first call to super.postValue
gives a type mismatchsealed class Clearable<out T> {
object Clear: Clearable<Nothing>()
data class Value<T>(val t: T): Clearable<T>()
}
Michael de Kaste
06/16/2020, 8:45 AMKroppeb
06/16/2020, 11:15 AMClearable<Nothing>
isn't a subtype of Clearable<T>
william
06/16/2020, 12:11 PMout T
, any of the type parameters can be a supertype of T
, which Nothing
is a supertype of everything.Kroppeb
06/16/2020, 1:31 PMwilliam
06/16/2020, 2:59 PMKroppeb
06/16/2020, 3:01 PMout T
, any of the type parameters can be a subtype of T
, which Nothing
is a subtype of everything.william
06/16/2020, 4:41 PM