Community
Participate
Working Groups
Through some recent fixes in sun's j2sdk1.4.1, certain forward references of static variables are allowed. The following code compiles and runs using 1.4.1's javac, but not in Eclipse 2.0: public class Test { public Test(){ super(); System.out.println(error); } public static void main (String args[]) { Test test = new Test(); } static { error = "Hello World"; } private static String error; } I looked for this in other bug reports but could not find it.
No, this is definitely new. Need to check the spec.
Jikes 1.15 rejects it, but Jikes 1.17 accepts it.
Olivier - can you please look for a URL to this bug in javac database ?
This is a link pointing to this problem. http://developer.java.sun.com/developer/bugParade/bugs/4459133.html If the reference is an assignement, then it should not complain about an invalid forward reference. See latest specs: http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#287406 Jacks test suite has some related tests.
Add CC
Indeed the spec is pretty clear, assignments should be allowed to perform on forward references.
Assignments will no longer complain about forward references. Fixed.
Verified.