I would like to do something like:
Class<List<String>> targetClass = List<String>.class;
but that construct does not compile.
The compiler is ok with the
Class<List<String>> targetClass;
declaration, but the compiler does not like
List<String>.class
Interestingly, the compiler (1.7) allows this:
Class<List<String>> targetClass = (Class<List<String>>) List.class;
but then of course complains about an unsafe cast.
Although it seems like it should be,
List<String>is not a class, so you cannot get the class object for that. Generics are only used to check at compile time. They are erased from the compiled bytecode.So, the best you can do is just,
From Effective Java, 2nd ed.,