“There is no instance of type variable R, so observable complies with observable” error when updating to rxjava2

I am trying to call the API using retreading and rxjava. When using rxjava 1, the following code seems to work well, but once I update to rxjava 2, I will receive this error:

Error:

APIE

Observable<HttpResult<List<Article>>> getList(@Query("key")String key);

The API request is completed here, which is where I received this error in the. Map operator

Observable cache=providers.getList().map(new HttpRsltFunc<List<Article>>());

Result class model:

private  class HttpRsltFunc<T> implements Func1<HttpResult<T>, T> {
       @Override
       public T call(HttpResult<T> httpResult) {   
           return httpResult.getData();
       }
   }

Edit:

When importing rx.observable instead of io.reactivex.observable, the code works normally

thank you

resolvent:

This happens because rxjava2 has migrated to its own functional interfaces, so you need to implement different interfaces instead of func1

And don't forget to update the transformation adapter to rxjava2 version: compile 'com. Square. Retrofit2: Adapter - rxjava2: latest. Version'

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>