In the following example, this program prints
with Sun JDK 6u7 however with Jet 6.4 it prints
Is there a recommended way to get the enclosing class?
This is needed for Enum.valueOf(enclosingClass, text) to work. You cannot use the MyEnum.YES.getClass() for example.
public class EnumTestMain {
public static void main(String... args) throws ClassNotFoundException {
Class yesClass = MyEnum.YES.getClass();
System.out.println("The enclosing class is " + yesClass.getEnclosingClass());
}
public enum MyEnum {
YES {
public String getName() {
return "Yes!";
}};
public abstract String getName();
}
}