I\'m trying to find a way to iterate through an enum\'s values while using generics. Not sure how to do this or if it is possible.
The following code illustrates
This is a hard problem indeed. One of the things you need to do is tell java that you are using an enum. This is by stating that you extend the Enum class for your generics. However this class doesn't have the values() function. So you have to take the class for which you can get the values.
The following example should help you fix your problem:
public > void enumValues(Class enumType) {
for (T c : enumType.getEnumConstants()) {
System.out.println(c.name());
}
}