-
Bug
-
Resolution: Fixed
-
P5
-
7
-
b128
-
generic
-
generic
-
Verified
Compiling
B b = new B() { static final int x; };
gives error
inner classes cannot have static declarations
but they can, provided the static declaration is a compile-time constant field (JLS8.1.3):
B b = new B() { static final int x = 1; }; // Compiles OK
(I'll update the JLS to say "unless they are constant variables (4.12.4)" rather than "compile-time constant fields (15.28)".)
B b = new B() { static final int x; };
gives error
inner classes cannot have static declarations
but they can, provided the static declaration is a compile-time constant field (JLS8.1.3):
B b = new B() { static final int x = 1; }; // Compiles OK
(I'll update the JLS to say "unless they are constant variables (4.12.4)" rather than "compile-time constant fields (15.28)".)
- relates to
-
JDK-4279339 Static members incorrectly permitted in anonymous classes
- Resolved
-
JDK-4214814 javac can compile static members in non-static inner classes
- Closed