I was hoping to declare in Enum type in a subclass and then access it from the super class. This is what I came up with, but it does not work:
class Subclass {
enum Pets {
CAT,
DOG;
}
Class<Pets> getEnumClass() {
return Pets.class;
}
}
class Superclass {
// This generates a warning:
abstract Class<? extends Enum> getEnumClass();
void PrintEnumNames() throws InstantiationException, IllegalAccessException {
Class<? extends Enum> enumClass = getEnumClass();
Enum newEnum = enumClass.newInstance();
for( Enum iEnum : newEnum.values()) { // newEnum.values() isn't available
System.out.printf("%s", iEnum.toString());
}
}
}