How to hide Generic type parameters from implementing class of a Callback interface
<p>I'm writing an API on Android that will be used by an existing application, which I'm going to call the client. There is a lot of client code and I don't really want to modify it. Right now the API implements a callback method as an interface. In order to save my self from writing lots of boiler plate code I decided to use generics and extensible classes. This design decision is making my API's Callback interface use generics. In turn this is causing the complier to flag the client as needing to to specify type parameters where the callback is implemented. I don't want to cause the client to have to use type parameters. In effect I want to shield the client code from having to specify types and hopefully prevent the client from specifying the wrong type.</p>

<p>Here is an example:</p>

<p>Example of an extensible API class to encapsulate basic functionality:</p>

<pre><code>public abstract class BaseAPI&lt;T&gt; {
   Callback mCallBack;   

   public BaseAPI(Callback&lt;T&gt; callback) {
      mCallBack = callback;
   }

   public void doSomething() {
      T response = getResponse();
      if (mCallBack != null) {
         mCallBack.onCallback(response)
      }
   }

   public abstract T getResponse();

   public interface Callback&lt;T&gt; {
      public void onCallback(T response);
   }
}
</code></pre>

<p>Example class that extends BaseAPI:</p>

<pre><code>public class ExampleAPI extends BaseAPI&lt;String&gt; {

   public ExampleAPI(Callback&lt;String&gt; callback) {
      super(callback):
   }

   public String getResponse() {
      String response = "blah";
      return response;
   }
}
</code></pre>

<p>Example client code (This is how I want it to look):</p>

<pre><code>public class ClientView extends Activity implements Callback {
   TextView mTextView;

   onCreate() {
      //pretend normal setup code is here

      new ExampleAPI(this).doSomething();
   }

   onCallback(String response) {
       mTextView.setText(response);
   }
}
</code></pre>

<p>Example client code (This is the complier wants it to look):</p>

<pre><code>public class ClientView extends Activity implements Callback&lt;String&gt; {
   TextView mTextView;

   onCreate() {
      //pretend normal setup code is here

      new ExampleAPI(this).doSomething();
   }

   onCallback(String response) {
       mTextView.setText(response);
   }
}
</code></pre>

<p>Any ideas? Does this make sense?</p>
