okarm
09/01/2020, 3:28 PMB
as a value of StateFlow<A>
. I would not expect that to be possible. The code not only compiles, it actually runs in the Playground without a run-time exception.octylFractal
09/01/2020, 5:10 PMval a = flow.value
I would expect an exception as kotlin should introduce a cast thereokarm
09/01/2020, 5:31 PMB
to LiveData<A>
. But it it has no problem setting B
as value of StateFlow<A>
wasyl
09/01/2020, 7:11 PMMutableStateFlow
doesn’t perform any checks when setting value of a wrong type 🤔octylFractal
09/01/2020, 7:55 PMokarm
09/01/2020, 8:14 PMpublic abstract class LiveData<T>
vs public interface StateFlow<out T>
- There's no out-projection in LiveDataoctylFractal
09/01/2020, 8:39 PMLiveData
is a Java class, not a Kotlin one?out T
allows such things as:
interface Source<out T> {
fun nextT(): T
}
fun demo(strs: Source<String>) {
val objects: Source<Any> = strs // This is OK, since T is an out-parameter
// ...
}
StateFlow<Any>
from the flow
and allow the unsafe setMutableStateFlow
doesn't declare out T
, but just T
-- since it prevents input from being promoted to Any
araqnid
09/01/2020, 9:36 PM