There is not really a point in having Class<List<String>>
, since it would be equivalent to Class<List<Integer>>
(both being a reference to the raw List due to erasure).
Having said that, if your intention is to represent the List<String>
type, this is possible, see TypeLiteral of Google Guice.
TypeLiteral<List<String>> type = new TypeLiteral<List<String>>() {};
System.out.println(type.getType()); //should print List<String>
The mechanism that makes it possible is reflection on static type declarations, in either class definition (class X extends Foo<Y>
, Y is available through reflection, it is preserved in the bytecode), method definitions, etc. TypeLiteral uses the former, you may notice that it creates a brand new class, so the net effect is that your type parameter gets preserved. It's a nice workaround when you are really fighting against erasure.