Use List.class
. Because of type erasure type parameters to Java classes are entirely a compile-time construct - even if List<String>.class
was valid syntax, it would be the exact same class as List<Date>.class
, etc. Since reflection is by nature a runtime thing, it doesn't deal well with type parameters (as implemented in Java).
If you want to use the Class object to (for example) instantiate a new List instance, you can cast the result of that operation to have the appropriate type parameter.
List<String> list = (List<String>)(ArrayList.class.newInstance());
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…