I want to parameterize a class with an enum, then in the constructor of the class create an Array having the size of the number of elements in the enum.
I created the class like this:
public class LogLine <T extends Enum<T>> {
And then in the constructor I tried writing this:
public LogLine(){
numberOfElementsInEnum = T.values().length;
//then I would create the Array based on the numberOfElementsInEnum variable
It doesn't work. The compiler doesn't see the values method. I tried with T extending String instead of Enum. All static method are then accessible. What is the issue here?
valuesis not a static method onEnum.new Torinstanceof Tare illegal in Java because generic type information is largely absent at run time. It seems, though, that your use case does not absolutely require the generic type at run time.