I’m trying to achieve the following but I’m getting error. Trying to understand what’s going wrong here and what should be done to get around the error. I want to support both nullable and non-nullable here.
class TriggeredLiveData<T, V>(value: V) : LiveData<V>(value) {
private val trigger = MutableLiveData<T>()
...
fun pullTrigger(payload: T) {
trigger.postValue(payload) // Error: Expected non-nullable value
}
}
Also here is the signature for both MutableLiveData
and LiveData
public class MutableLiveData<T> extends LiveData<T> {
/**
* Creates a MutableLiveData initialized with the given {@code value}.
*
* @param value initial value
*/
public MutableLiveData(T value) {
super(value);
}
/**
* Creates a MutableLiveData with no value assigned to it.
*/
public MutableLiveData() {
super();
}
@Override
public void postValue(T value) {
super.postValue(value);
}
@Override
public void setValue(T value) {
super.setValue(value);
}
}
public abstract class LiveData<T> {
...
protected void postValue(T value) { ... }
}