I am trying to make a call to API using retrofit and rxJava
. The code below seems to work well when using RxJava 1
, but once I updated to RxJava 2
I am getting this error:
Error :
No Instance of type variable R exist so that Observable conforms to Observable
Api
Observable<HttpResult<List<Article>>> getList(@Query("key")String key);
Api request done here, and this is where I get this error inside .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 just fine.
Thank you
This is happening because rxjava2 migrated to their own functional interfaces, so you need to implement different interface instead of Func1
.
And don't forget to update your retrofit adapter to rxjava2 version:
compile 'com.squareup.retrofit2:adapter-rxjava2:latest.version'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With