Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot resolve method 'subscribe(anonymous io.reactivex.functionx.Consumer<java.util.List<...>>)' in rxjava2?

Tags:

rx-java2

after toList operator performs, original Flowable<<\List>> converts to Single<<\List>>. and it turns out if I create Consumer to subscribe to Single, the Consumer value type cannot be changed except Object?

 @Override
public void loadBannerData(final ADFilterType adFilterType) {
    remoteListDataSource.getBannerListData(adFilterType)
            .flatMap(new Function<List<BannerBeanList.BannerBean>, Publisher<?>>() {
                @Override
                public Publisher<?> apply(List<BannerBeanList.BannerBean> bannerBeen) throws Exception {
                    return Flowable.fromIterable(bannerBeen);
                }
            })
            .toList()
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
           /******************************Consume Value Type**************************
            .subscribe(new Consumer<List<BannerBeanList.BannerBean>>() {
                @Override
                public void accept(List<BannerBeanList.BannerBean> bannerBeens) throws Exception {
                    mainTabView.showMainBanner(bannerBeens);
                }
            });
          *****************************************************************************/
}
like image 643
Qin Avatar asked Nov 22 '16 10:11

Qin


1 Answers

From my comment: this happens because you have Publisher<?> instead of Publisher<BannerBeanList.BannerBean> in your code. Often IDEs can't infer types of lambdas or functional interfaces and you'll end up with ? or Object as their type when using some generate/convert refactoring function.

like image 196
akarnokd Avatar answered Oct 19 '22 15:10

akarnokd