immutable property
LiveData<T>
get
immutable
Returns this MutableLiveData as a LiveData reference.
This doesn't create a true immutable copy, but returns the same instance typed as LiveData. Useful for exposing the LiveData through a public getter while keeping the mutable field private.
Note: Callers can still cast back to MutableLiveData if needed.
Example:
class MyViewModel extends ViewModel {
final _data = MutableLiveData(0);
LiveData<int> get data => _data.immutable;
// or simply: LiveData<int> get data => _data;
}
Implementation
LiveData<T> get immutable => this;