I have a Java class with a generic type. In the business logic of that class, I need to refer to the Class
object of the generic type. Therefore, the constructor get the Class
object passed as argument:
public class MyClass<GENERIC_TYPE>{
private Class<GENERIC_TYPE> genericTypeClass;
public MyClass(Class<GENERIC_TYPE> genericTypeClass){
this.genericTypeClass=genericTypeClass;
}
}
I create the instance(s) of this class using a CDI producer, whose squeleton looks like
public class MyClassProducer{
@Produces
MyClass<GENERIC_TYPE> createMyClass(InjectionPoint injectionPoint){
Class<GENERIC_TYPE> genericTypeClass = ????
return new MyClass(genericTypeClass);
}
}
How do I retrieve genericTypeClass
?
Solution is a two liner: