【发布时间】:2020-06-12 15:33:01
【问题描述】:
当尝试从 Flow 收集时,类型突然不匹配,它正在工作,然后突然启动。
在我的视图模型中:
class MyViewModel: ViewModel() {
lateinit var river: Flow<Int>
fun doStuff() {
river = flow {
emit(1)
}.flowOn(Dispatchers.Default)
.catch {
emit(0)
}
}
}
然后在我的活动中,我有以下内容:
lifecycleScope.launch {
viewModel.river.collect { it ->
// this whole collect is what has the error.
}
}
但是collect 给出了错误:Type mismatch: inferred type is () -> Unit but FlowCollector<Int> was expected。
怎么会这样?
【问题讨论】:
标签: android kotlin kotlin-coroutines kotlin-flow