以下代码中的过滤器试图过滤掉奇数,但我无法编译代码,因为它在抱怨
错误:(114, 25) 错误:不兼容的类型:> 无法转换为 Predicate
当我将 rxjava 1 与 Func1 一起使用时很好,我怎样才能使它与 rxjava 2 一起使用?
List<Integer> ints = new ArrayList<>();
for (int i=1; i<10; i++) {
ints.add(new Integer(i));
}
Log.d("RxFlapmapActivity", "flapMapEx2 1,2,3,4,5,6,7,8,9");
Observable.just(ints)
.flatMap(new Function<List<Integer>, Observable<Integer>>() {
@Override
public Observable<Integer> apply(List<Integer> ints) {
return Observable.fromIterable(ints);
}
})
.filter(new Function<Integer, Boolean>() {
@Override
public Boolean apply(Integer integer) {
Log.d("RxFlapmapActivity", "flapMapEx2222222 filter out odd numbers.........");
return integer.intValue() % 2 == 0;
}
})
.flatMap(new Function<Integer, Observable<Integer>>() {
@Override
public Observable<Integer> apply(Integer integer) {
for (int i = 0; i < 1000000000; i++) {
}
return multiplyInt(integer, 2);
}
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<Integer>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onComplete() {
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
}
@Override
public void onNext(Integer integer) {
Log.d("RxFlapmapActivity", "flapMapEx2 onNext>>>" + integer.toString());
}
});