I have a class defined as follows:
public class GenericClass<T> {
private final Class<T> type;
public GenericClass(Class<T> type) {
this.type = type;
}
public Class<T> getMyType() {
return this.type;
}
}
With this class code, it is easy to instantiate a new class with a non-generic type. For instance:
GenericClass<String> c = new GenericClass<String>(String.class)
My question is the following. How to create a new instance of a class with a common type? Example:
GenericClass<List<String>> c = new GenericClass<List<String>>(...)
If I put List<String>.class, the compiler will give me an error. At compile time, what syntax should be used to indicate the constructor of the right class of the generic type?
source
share