Consider the following ways to expose MutableLiveData
:
Method A
class ThisViewModel : ViewModel() {
private val _someData = MutableLiveData(true)
val someData: LiveData<Boolean>
get() = _someData
}
// Decompiled Kotlin bytecode
public final class ThisViewModelDecompiled extends ViewModel {
private final MutableLiveData _someData = new MutableLiveData(true);
@NotNull
public final LiveData getSomeData() {
return (LiveData)this._someData;
}
}
Method B
class ThatViewModel : ViewModel() {
private val _someData = MutableLiveData(true)
val someData: LiveData<Boolean> = _someData
}
// Decompiled Kotlin bytecode
public final class ThatViewModelDecompiled extends ViewModel {
private final MutableLiveData _someData = new MutableLiveData(true);
@NotNull
private final LiveData someData;
@NotNull
public final LiveData getSomeData() {
return this.someData;
}
public ThatViewModel() {
this.someData = (LiveData)this._someData;
}
}
Is there a reason to use Method B over Method A?