如何将Flowable转换为Single?或者,如果有另一种方法使其在第一个感兴趣的响应之后停止发光.
我试过这个,但它似乎不起作用:
disposables.add(
repository.getAllSomethings()
.subscribeOn(SchedulerProvider.getInstance().computation())
.observeOn(SchedulerProvider.getInstance().ui())
.toSingle()
.subscribeWith(object : DisposableSingleObserver>() {
override fun onSuccess(t: List) {
}
override fun one rror(e: Throwable) {
}
})
getAllSomethings()返回一个Flowable< List< Something>>
在上面的代码中.subscribeWith()用红色下划线表示:
Type parameter bound for E in
fun !>!>!> subscribeWith(observer: E!): E!
is not satisfied: inferred type ! is not a subtype of SingleObserver!>!>!
解决方法:
好的,感谢@akarnokd,我在评论中看到了答案.
在那里我发现firstOrError()解决了我的问题.
即使我调用的单个对象是一个Flowable,IDE也没有抱怨.然而,看看上面的链接,toSingle()甚至不是一个有效的选择!
标签:android,rx-java2
来源: https://codeday.me/bug/20190715/1464837.html