FULL PRODUCT VERSION :
java version " 1.7.0_09 "
Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
The code below generates the following compile-time errors:
error: non-static variable i cannot be referenced from a static context
A { public int get() { return i; } }
error: i has private access in E
B { public int get() { return this.i; } }
And the lines C and D compile correctly. That is an inconsistent behaviour.
enum E {
A { public int get() { return i; } },
B { public int get() { return this.i; } },
C { public int get() { return super.i; } },
D { public int get() { return D.i; } };
private int i = 0;
E() { this.i = 1; }
public abstract int get();
}
REPRODUCIBILITY :
This bug can be reproduced always.
java version " 1.7.0_09 "
Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
The code below generates the following compile-time errors:
error: non-static variable i cannot be referenced from a static context
A { public int get() { return i; } }
error: i has private access in E
B { public int get() { return this.i; } }
And the lines C and D compile correctly. That is an inconsistent behaviour.
enum E {
A { public int get() { return i; } },
B { public int get() { return this.i; } },
C { public int get() { return super.i; } },
D { public int get() { return D.i; } };
private int i = 0;
E() { this.i = 1; }
public abstract int get();
}
REPRODUCIBILITY :
This bug can be reproduced always.
- duplicates
-
JDK-8236986 Inaccessible instance error in enum falsely flagged as static context
-
- Closed
-