I intend to create a function with the following signature –
public static List<? extends Model> getList(Model T, int numberOfItems, StringReader reader)
Now, inside this function, I want to create an ArrayList that will contain the same type of objects as T or any of its subclasses, i.e T could be a Model object or any of its subtypes.
So far, I tried –
List < ? extends T> list = new ArrayList();
But it didn’t work. How to get this to work?
You’ll have to pass in the
Classinstance as a type marker. Something like this:I don’t know how you want to use the
StringReaderso I left it aside. Call the method with a class literal. Say you’ve got aSubModel extends Model, then