title: How to create a generic return type for an abstract class override method
body: <p>I have an abstract class that gets implemented by Java and by Android.  This class has a method that needs to return a generic Cursor so that the implementations can return their respective cursors.</p>
  
  <p>My abstract class:</p>
  
  <pre><code>public abstract class DatabaseAdapter {
  
  protected abstract com.domain.database.Cursor&lt;?&gt; executeQuery(String command);      
  
  }
  </code></pre>
  
  <p>The cursor type:</p>
  
  <pre><code>public final class Cursor&lt;T&gt; {
  
  private T value = null;
  
  public void setValue(T value) {
      this.value = value;
  }
  
  public T getValue() {
      return value;
  }
      }
  </code></pre>
  
  <p>As stated earlier, I want the implementing method to return either a Java cursor or and Android cursor depending upon the situation.  I can create the abstract classes just fine but when I try to implement, I get a compile error.  I am apparently not understanding polymorphism very well here.</p>
  
  <p>The implementing method</p>
  
  <pre><code>public Cursor executeQuery(String query){
  Cursor cursor = db.rawQuery(query, selectionArgs);
  return cursor;      
  }
  </code></pre>
  
  <p>where Cursor is <strong>android.database.Cursor</strong></p>