I have a class A
that depends on a type parameter E
, which I want to bound as an enum
. This is what I did:
public class A<E extends Enum<E>> {}
But then I can't iterate over the elements of the enum. Here is an example:
public class A<E extends Enum<E>> {
public void display() {
for(E e : E.values())
System.out.println(e);
}
}
It doesn't work because it Cannot resolve method 'values' in 'E'.
What should I do instead to have the type parameter bounded to be an enum
which can really behave like an enum
?
Edit:
All the solutions in the linked question are not applicable, since inside of the display
method I don't have access to any concrete object of type E
.