title: Subclasses of a class that implements a generic interface
body: <p>I'm working with Google Web Toolkit, and I'm having problems implementing a generic interface. I'm not really familiar with generics, doing an upgrade on someone else's code here.</p>
  
  <p>Here's what I want to do: I want to have an implementation of a generic callback interface that does some logging, and then subclass that implementation in order to handle specific callback scenarios.</p>
  
  <p>The interface is something like this:</p>
  
  <pre><code>public interface AsyncCallback&lt;T&gt; {
      void MethodFromAsyncCallback(T result);
  }
  </code></pre>
  
  <p>The abstract and concrete implementations look something like this:</p>
  
  <pre><code>class CallbackBase implements AsyncCallback&lt;Object&gt; {
      public abstract void doStuff(Object result);
  
      public void MethodFromAsyncCallback(Object result) {
          // IMPORTANT STUFF
          // here are things I would like to do for all callbacks, hence the superclass.
  
          // Then we do the subclass specific things.
          doStuff(result);
      }
  }
  
  class SpecificCallback extends CallbackBase
  {
      public void doStuff(Object result) {
          Integer i = (Integer)result;
          // do stuff with i
      }
  }
  </code></pre>
  
  <p>The callbacks are required to be fired from</p>
  
  <pre><code>public interface MyServiceAsync {
      public void DoSomeThing(AsyncCallback&lt;Integer&gt;);
  }
  </code></pre>
  
  <p>And then it all comes together in a call that looks like this:</p>
  
  <pre><code>MyServiceAsync myService = (MyServiceAsync)GWT.create(MyServiceAsync.class);
  myService.DoSomeThing(new SpecificCallback());
  </code></pre>
  
  <p><strong>And here's where we have a problem!</strong></p>
  
  <p>When the <code>GWT.create()</code> implements the interface I created, it demands that the type given to <code>AsyncCallback</code> is specified (matches a type elsewhere, outside the scope of this question), hence making <code>DoSomething(AsyncCallback&lt;Integer&gt;)</code> an Integer rather than an Object. This is beyond my control. </p>
  
  <p>It complains that <code>DoSomething()</code> takes <code>AsyncCallback&lt;Integer&gt;</code>. I'm giving it something that inherits from something that is an <code>AsyncCallback&lt;Object&gt;</code>. I guess with generics, concepts of inheritance get somewhat broken?</p>
  
  <p><strong>So my question is this:</strong></p>
  
  <p><em>Either</em> how can I mush this together so that <code>DoSomething()</code> will recognize that that <code>SpecificCallback</code> meets it's requirements,</p>
  
  <p><em>or</em> how can I structure the relationship between <code>CallbackBase</code> and <code>SpecificCallback</code> so that duplicate code is avoided, but <code>SpecificCallback</code> implements <code>AsyncCallback&lt;Integer&gt;</code> directly?</p>
  
  <p>Thanks.</p>