I saw some questions like this but different from my case.I want to set generated class at build time as generic type at runtime. here is code.
//employee class is generated at build time
void function(Class<?> employee)
{
// I want to set class as generic type like this
List<employee> emps= new ArrayList<employee>(employee);
}
how to do this?
You can't.
Generics are all mapped to java.lang.Object
on compilation by a process called type erasure .
You can only build things that are checked at compile time: consider using Class<? extends ...>
Class<? extends ...>
notation.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.