Community
Participate
Working Groups
The following code should be rejected, because the constant is not yet initialized when referenced inside its initializer. public enum X { A() { X a = A; void foo() { System.out.println(String.valueOf(a)); } }; abstract void foo(); public static void main(String[] args) { A.foo(); } } We accept it and return null at runtime.
Detection for enum static field references inside initializer did not handle enum constant body (direct superclass of declaringClass of field).
Added EnumTest#test120. Fixed
Verified in 3.2 M1 with build I20050808-2000. javac does not complain (at least javac 1.5.0_04-ea), but it should according to JLS 8.9 - in this case, self reference of A in its constructor.
Verified using M20050923-1430 for 3.1.1