Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

abstract class implementation Call<T> #1059

Closed
gintechsystems opened this issue Sep 6, 2015 · 4 comments
Closed

abstract class implementation Call<T> #1059

gintechsystems opened this issue Sep 6, 2015 · 4 comments

Comments

@gintechsystems
Copy link

This is more of a question because I may be doing this wrong, but I have created a custom class because I wanted to add a few methods that are not part of Call (such as a tag so I can cancel the request from anywhere in my apps). Maybe there is a better approach to this, but my code follows and I receive the following error:

Error:(1822, 10) error: clone() in Object cannot implement clone() in Call
attempting to assign weaker access privileges; was public
where T is a type-variable:
T extends Object declared in interface Call

abstract class RemoteJSONServiceCall implements Call {
AMFParameters amfParameters = null;
}

private RemoteJSONServiceCall createRetrofitCall(final AMFParameters params) {
if (Connectivity.isConnected(visnetawrap)) {
RemoteJSONServiceCall newCall = amfService.amfcall(params);
newCall.amfParameters = params;
callsList.add(newCall);
return amfService.amfcall(params);
}
return null;
}

@JakeWharton
Copy link
Member

You need to add a clone() method which returns a new instance.

@JakeWharton
Copy link
Member

Here's an example:

public final class AppCall<T> implements Call<T> {
  private final Call<T> delegate;
​
  public AppCall(Call<T> delegate) {
    this.delegate = delegate;
  }
​
  private void handleResponseBody(T body) {
​    // TODO whatever
  }
​
  @Override public Response<T> execute() throws IOException {
    Response<T> response = delegate.execute();
    if (response.isSuccess()) {
      handleResponseBody(response.body());
    }
    return response;
  }
​
  @Override public void enqueue(final Callback<T> callback) {
    delegate.enqueue(new Callback<T>() {
      @Override public void onResponse(Response<T> response) {
        if (response.isSuccess()) {
          handleResponseBody(response.body());
        }
        callback.onResponse(response);
      }
​
      @Override public void onFailure(Throwable t) {
        callback.onFailure(t);
      }
    });
  }
​
  @Override public void cancel() {
    delegate.cancel();
  }
​
  @Override public Call<T> clone() {
    return new AppCall<>(delegate.clone());
  }
}

Note the clone method and the fact that it also clones the delegate.

@gintechsystems
Copy link
Author

Thank you!

@albert0m
Copy link

I tried to do the same thing, but I get this error:

Could not locate call adapter for .....

and then

Unable to create call adapter for .....

this is a piece of my code

            Retrofit client = new Retrofit.Builder()
                    .baseUrl(baseUrl)
                    .client(okClient)
                    .addConverterFactory(GsonConverterFactory.create())
                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                    .build();

what am I doing wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants