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);
}
}
}
As Eric said, enums are implicitly static. To do what you want, add a method, callOuterMethod(OuterClass oc)
that calls oc.outerMethod(data)
to do what you want:
public enum InnerEnum {
OPTION1("someData"),
OPTION2("otherData");
final String data;
InnerEnum(String data) {
this.data = data;
}
void callOuterMethod(OuterClass oc) {
oc.outerMethod(data);
}
}