文档非常清楚地说明了 Observable 的替代方案的作用:
The Single class implements the Reactive Pattern for a single value response. See Observable for the implementation of the Reactive Pattern for a stream or vector of values. Single behaves the same as Observable except that it can only emit either a single successful value or an error (there is no "onComplete" notification as there is for Observable) Like an Observable, a Single is lazy, can be either "hot" or "cold", synchronous or asynchronous.
但我看不出它有时可能比 Observable 更简单的原因,在哪里以及为什么使用它?
最佳答案
在某些情况下,可观察对象仅返回单个项目并结束(或错误)是有意义的。 This blog post简单地解释一下。
关于rx-java - 为什么要使用 RxJava 中的新功能 Single?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36152475/