Jump to content
Excelsior Forums
Sign in to follow this  
peter__lawrey

getEnclosingClass() returns null

Recommended Posts

In the following example, this program prints

The enclosing class is EnumTestMain$MyEnum

with Sun JDK 6u7 however with Jet 6.4 it prints

The enclosing class is null

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();
    }
}

Share this post


Link to post
Share on other sites

Hi,

I have reproduced the problem, thanks for providing this example.

We will work on it. Please contact the support team (java@excelsior-usa.com) if you need a hotfix.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×