Class instance of generic type T
(, en)
Due to
Type Erasure it is
really difficult to get a Class<T>
instance of T
.
Common solution
is to supply the Class<T>
object as constructor argument.
public class Foo<T> {
Class<T> clazz;
public Foo(Class<T> clazz) {
this.clazz = clazz;
}
}
Instantiate with new Foo<>(String.class);