-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
8, 13
-
generic
-
generic
A DESCRIPTION OF THE PROBLEM :
https://stackoverflow.com/questions/41311361/nested-enum-is-static#41311454 describes the following program:
enum EnumImpl {
B {
public void method() {
System.out.println(s);
}
//public static int b; //(2)Illegal static declaration in inner class
};
public abstract void method();
private int s;
}
The compiler error message is:
non-static variable s cannot be referenced from a static context
This message is misleading. If "private" is removed from the declaration of s, the class compiles as it should. The reason for failure should be described as "s has private access in EnumImpl".
FREQUENCY : always
https://stackoverflow.com/questions/41311361/nested-enum-is-static#41311454 describes the following program:
enum EnumImpl {
B {
public void method() {
System.out.println(s);
}
//public static int b; //(2)Illegal static declaration in inner class
};
public abstract void method();
private int s;
}
The compiler error message is:
non-static variable s cannot be referenced from a static context
This message is misleading. If "private" is removed from the declaration of s, the class compiles as it should. The reason for failure should be described as "s has private access in EnumImpl".
FREQUENCY : always
- duplicates
-
JDK-8028361 Incorrect compile error: enum instance accessing private members
-
- Open
-