Q:

Creating an Arraylist of the specified parameter's type or its subtype

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?

A:

You'll have to pass in the Class instance as a type marker. Something like this:
public static <T extends Model> List<T> getList(
    Class<T> c, int numberOfItems, StringReader reader)
{
  final List<T> l = new ArrayList<T>();
  try { for (int i = 0; i < numberOfItems; i++) l.add(c.newInstance());
  } catch (Exception e) { throw new RuntimeException(e); }
  return l;
}

I don't know how you want to use the StringReader so I left it aside. Call the method with a class literal. Say you've got a SubModel extends Model, then
final List<SubModel> l = getList(SubModel.class, 10, reader);

