0
Hỏi về convert Java sang Kotlin
Mình đang có 1 đoạn code Java
public <R> Observable<?> adapt(Call<R> call) {
return ((Observable) wrapped.adapt(call))
.onErrorResumeNext(new Func1<Throwable, Observable>() {
@Override
public Observable call(Throwable throwable) {
throwable.printStackTrace();
return Observable.error(asRetrofitException(throwable));
}
});
}
Sau khi dùng Android Studio chuyển sang Kotlin thì mình được đoạn code
override fun <R> adapt(call: Call<R>): Observable<*> {
return (wrapped.adapt(call) as Observable<*>)
.onErrorResumeNext(Func1<Throwable, Observable<*>> { throwable ->
throwable.printStackTrace()
Observable.error(asRetrofitException(throwable))
})
}
Nhưng nó đang báo lỗi ở onErrorResumeNext và Observable.error cụ thể:
- onErrorResumeNext
Error:(36, 22) None of the following functions can be called with the arguments supplied:
public final fun onErrorResumeNext(p0: ((Throwable!) -> Observable<out Nothing!>!)!): Observable<out Any!>! defined in rx.Observable
public final fun onErrorResumeNext(p0: Observable<out Nothing!>!): Observable<out Any!>! defined in rx.Observable
public final fun onErrorResumeNext(p0: Func1<Throwable!, out Observable<out Nothing!>!>!): Observable<out Any!>! defined in rx.Observable
- Observable.error
Error:(38, 36) Type inference failed: Not enough information to infer parameter T in fun <T : Any!> error(p0: Throwable!): Observable<T!>!
Please specify it explicitly.
Cao thủ nào support mình với ạ
Thêm một bình luận
1 CÂU TRẢ LỜI
+1
.onErrorResumeNext{ throwable ->
throwable.printStackTrace()
Observable.error(asRetrofitException(throwable))
}
- Bạn cần đưa type vào diamond operator
<>
Observable.error<RetrofitException>(asRetrofitException(throwable))