RxJava 2几乎已经发布,我想从RX 1.2.0迁移到2.0.0,但我注意到RxJava 2中没有Func0接口.
开发人员应该在RxJava 2中使用哪些代替Func0?
Ste*_*eve 17
RxJava2使用JDK的Callable接口(https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Callable.html)
Observable.defer示例(http://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Observable.html#defer(java.util.concurrent.Callable))
Observable.defer(new Callable<ObservableSource<MyObject>>() {
@Override
public ObservableSource<MyObject> call() throws Exception {
return Observable.just(new MyObject());
}
});
Run Code Online (Sandbox Code Playgroud)
根据他们对RxJava 1.x和2.x之间的变化的阐述:
We followed the naming convention of Java 8 by defining
io.reactivex.functions.Functionandio.reactivex.functions.BiFunction, plus renamingFunc3-Func9intoFunction3-Function9respectively. TheFuncNis replaced by theFunction<Object[], R>type declaration.In addition, operators requiring a predicate no longer use
Func1<T, Boolean>but have a separate, primitive-returning type ofPredicate<T>(allows better inlining due to no autoboxing).The
io.reactivex.functions.Functionsutility class offers common function sources and conversions toFunction<Object[], R>.
| 归档时间: |
|
| 查看次数: |
3984 次 |
| 最近记录: |