Created
December 28, 2019 21:29
-
-
Save RBusarow/85200b47cd50258c86b77779c1a910a1 to your computer and use it in GitHub Desktop.
nullability-safe Kotlin version of MutableLiveData
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Suppress("UNCHECKED_CAST") | |
class MutableLiveData2<T>(value: T) : LiveData<T>(value) { | |
override fun getValue(): T = super.getValue() as T | |
public override fun setValue(value: T) = super.setValue(value) | |
public override fun postValue(value: T) = super.postValue(value) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This seems to be a great alternative to avoid null checks while retrieving values in mutable live data. But i m getting an issue where this can't be used in two-way data binding. I get the following error
If possible, could you please have a look on what can be done here.