0

I've tried searching but haven't found this exact problem. I am trying to create an abstract type that implements RxJava's Observer. This new type, RemoteObserver, will wrap a Retrofit2 Response object, which wraps some generic type. My code is bellow, with the errors in comments.

I need type A since this generic is the type that will be returned by response.body() and used in onSuccess(..).

public abstract class RemoteObserver<A, T extends Response<A>> implements Observer<T<A>> { // Error: Type 'T' does not have Type Parameters

    @Override
    public final void onNext(@NonNull Response response) {
        switch (response.code()) {
            case HttpsURLConnection.HTTP_OK:
            case HttpsURLConnection.HTTP_CREATED:
            case HttpsURLConnection.HTTP_ACCEPTED:
            case HttpsURLConnection.HTTP_NOT_AUTHORITATIVE:
                if (response.body() != null) {
                    onSuccess(response.body()); // Error: onSuccess(A) cannot be applied to (java.lang.Object)
                }
                break;

            case HttpsURLConnection.HTTP_UNAUTHORIZED:
                onUnauthorized();
                break;

            default:
                onError(new Throwable("Default " + response.code() + " " + response.message()));
        }
    }

    public abstract void onSuccess(A response);

    public abstract void onUnauthorized();

    public abstract void onError(Throwable T);
}

Any help would be much appreciated.

sbearben
  • 323
  • 6
  • 16

0 Answers0