another one :sweat_smile: it's not possible to ins...
# rx
i
another one 😅 it's not possible to instantiate
LiveData
with a fixed value (like `Observable`'s
just
), without having to use
MutableLiveData
?
k
I am not sure about how
LiveData
works but based on the docs LiveData has a default value constructor. https://developer.android.com/reference/androidx/lifecycle/LiveData.html#LiveData(T) Is that what you are looking for?
i
that doesn't work, because
LiveData
is an abstract class @kioba
which actually answers the question
there's no non-mutable subclass apparently
so it's not possible
k
sorry, I haven’t used LiveData but you might have more luck in the #android channel
m
@iex simplest factory method would solve your problem
Copy code
fun <T> LiveData(initValue: T): LiveData<T> = MutableLiveData<T>().apply { value = initValue }
i
@Maciek that's convenient but a hack kinda 😛
but yeah why not
would probably not capitalize the method's name though
m
to be honest capitalized letter is also kinda a pattern, at least in kotlin standard library 😉 here's the factory method for list from standard library
Copy code
public inline fun <T> List(size: Int, init: (index: Int) -> T): List<T> = MutableList(size, init)