Java Generics Pass . Class reference

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
分享
二维码
< <上一篇
下一篇>>