The code shown below does work because the method values() is static. My question is how can I achieve what the code below would do if B was not generic.
class A<B extends Enum<B>> {
public A() {
for (B b : b.values()) {
}
}
}
I can think of two solutions:
- pass the enum values into A’s constructor
- make B implement an interface that defines a method for obtaining the enum values.
Both seem messy to me. Anyone have any better solutions?
Try using getEnumConstants()