Idiomatic way to expose a property using a more narrow type

Nice, @Wasabi375, thanks. I hope it comes to a satisfying resolution in the near future.

Exposing MutableLiveData as LiveData is the reason I came here.

For that particular case you can sometimes just initialize mutably but store an immutable property, like so:

val liveData: LiveData<Data> = MutableLiveData<Data>().apply {
    observableData.addListener { newValue ->
        value = newValue
    }
}
2 Likes