[RESOLVED] What's the difference between casting to `StateFlow` vs `asStateFlow` ? :thread:
t
[RESOLVED] What's the difference between casting to
StateFlow
vs
asStateFlow
? ๐Ÿงต
message has been deleted
Which one is recommended/preferred?
d
The latter. I think it's because it prevents down casting to the
MutableStateFlow
.
โœ… 2
j
If you check the implementation,
asSharedFlow
and
asStateFlow
actually wrap your flow in a read-only instance. So people cannot down cast back to a mutable one and potentially mess up your state
โœ… 2
t
Understood ๐Ÿ™‡โ€โ™‚๏ธ
u
I use the cast. Unless youre a library or something