Alex Rivera | Logout

access outer class from inner nested enum

Asked 2011-12-10T16:34:29.533
25

Is There a Way to Access the Outside?

public class OuterClass  {
    String data;

    public void outerMethod(String data) {
         this.data = data;
    }

    public enum InnerEnum {
        OPTION1("someData"),
        OPTION2("otherData");

        InnerEnum(String data) {
              // Does not work:             
              OuterClass.this.outerMethod(data);
        }
    }
}
Edit
Report

1 Answer

10

Can't do that. The enum is implicitly static, even though you didn't declare it to be. See similiar question/answer:

"Nested enum types are implicitly static. It is permissable to explicitly declare a nested enum type to be static."

In Java, are enum types inside a class static?

answered 2011-12-10T16:42:37.027

Your Answer