I am trying to construct an instance of a generic class, with a type parameter. For example if have ArrayList.class
and I want to initialize it with class String.class
, how do I do that? I understand I can use ArrayList.class.newInstance()
to create a new instance, but I can't pass in a type parameter. I want to do new ArrayList<String>
, but instead of for that specific example, any class that has a type parameter.
Specifically, I am trying to implement testing of different implementations of an interface, through subclassing of a JUnit test.