I have a set of basic classes, ei:
public class Item{
}
I want to add feature to extend basic class with Storable ability:
- new parameter to keep data from storage in an object
- new static method to load objects from storage
I created an abstract class Storable:
public abstract class Storable{
private StorageRow str;
public void setStorageRow(StorageRow row){
str = row;
}
public static ArrayList<? extends Storable> getAll(){
ArrayList<Storable> ans = new ArrayList<Storable>();
Class<Storable> extenderClass = ??????
ArrayList<StorageRow> rows = Storage.get(llallala);
for(StorageRow row : rows){
Object extender = extenderClass.newInstance();
// Now with reflection call to setStorageRow(row);
}
return ans;
}
}
Now I extend my basic class with Storable:
public class Item extends Storable{}
The call is:
ArrayList<Item> items = (ArrayList<Item>) Item.getAll();
The main question is: Now I'm inside static method getAll of superclass. How to get a subclass?