The accepted answer to this question describes how to create an instance of T
in the Generic
class. This involves passing in a Class<
W may not be available due to type erasure. You should require that a Class
is passed into the method. You get a class object and its generic ensures that only W
and no subclass is passed in, due to covariance.
public InputField(String labelText, Class cls)
{
super(new String[] {labelText}, cls);
}
will take W.class
but not WSubtype.class
.