Java Generics Pass . Class reference
•
Java
I need to call a super constructor that requires me to pass a generic type Class reference How can I achieve this in Java?
I want to have
Class<List<MyType>>
Since generics are erased at run time, I don't know how to satisfy constructors
List<MyType>.class // does not work ;-)
Solution
Like this (convert to class raw type first):
@SuppressWarnings({ "unchecked","rawtypes" }) Class<List<MyType>> clazz = (Class) List.class
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码