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.
My abstract class:
public abstract class DatabaseAdapter {
protected abstract com.domain.database.Cursor<?> executeQuery(String command);
}
The cursor type:
public final class Cursor<T> {
private T value = null;
public void setValue(T value) {
this.value = value;
}
public T getValue() {
return value;
}
}
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.
The implementing method
public Cursor executeQuery(String query){
Cursor cursor = db.rawQuery(query, selectionArgs);
return cursor;
}
where Cursor is android.database.Cursor
I guess you can remove
com.domain.database.Cursor, but I may be wrong.My solution is to make
DatabaseAdaptergeneric, notCursor.Then you implement like this: