Can't resolve the method subscription (anonymous io.reactivex.functionx.Consumer <java.util.List <... >>) 'in rxjava2?

after executing the toList statement, the original Flowable <\ List → is converted to Single <<\ List →. and it turns out that if I create a Consumer to subscribe to Single, the type of consumer value cannot be changed except for 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);
                }
            });
          *****************************************************************************/
}
+4
source share
1 answer

From my comment: this is because there is Publisher<?>instead in the code Publisher<BannerBeanList.BannerBean>. Often, IDEs cannot infer types of lambda or functional interfaces, and in the end you get? or Object as their type when using some generate / convert regeneration function.

+5
source

Source: https://habr.com/ru/post/1661567/


All Articles