我有一个像这样的密封类
sealed class LoadState {
class Loading : LoadState()
class Success : LoadState()
class Fail : LoadState()
}
我将密封类与 LiveData 一起使用,它可以工作
open class BaseViewModel: ViewModel() {
// val loadState by lazy {
// MutableLiveData<LoadState>()
// }
val loadState by lazy {
MutableStateFlow(LoadState())
}
}
但是当我将 MutableLiveData 更改为 MutableStateFlow 时,我收到这样的警告
Sealed types cannot be instantiated
那么,如何在 MutableStateFlow 中使用密封类?