From Effective Java:
There are two minor exceptions to the rule that you should not use raw types in new code, both of which stem from the fact that generic type information is erased at runtime. You must use raw types in class literals. The specification does not permit the use of parameterized types (though it does permit array types and primitive types). In other words,
List.class
,String[].class
, and int.class are all legal, butList<String>.class
and List<?>.class
are not.