Community
Participate
Working Groups
Build Identifier: 20090920-1017 For example » static final int A = A; generates "Cannot reference a field before it is defined" error (CORRECT), but » class C » { » static final int A = C.A; » } does only generate a "The assignment to variable * has no effect" warning (INCORRECT), and A is give the default value (in the case 0). Reproducible: Always Steps to Reproduce: 1. Declare a class, e.g. C 2. In this class declare a static constant, e.g A 3. On declaration, assign C.A to A
This also compiles without error in javac. I suspect you've hit on a corner case in the Java Language Spec, but I'll leave it to the JDT Core folks to determine.
Checking http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.3.2.3 it appears that qualified references are accepted. Only simple references are rejected. Srikanth, last word to you.
(In reply to comment #2) > Checking > http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.3.2.3 it > appears that qualified references are accepted. > Only simple references are rejected. Isn't there a bug even in the JLS? The first sentence states that checking for this particular problem is only performed if all four requirements are met. Thus if any of the four requirements is not met we're good without checking textual order. The next sentence says: "A compile-time error occurs if any of the four requirements above are not met." which to me sounds like a contradiction. Should we silently ignore that sentence?
(In reply to comment #2) > Checking > http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.3.2.3 it > appears that qualified references are accepted. > Only simple references are rejected. Indeed, there is even an example that explicitly legitimizes the qualified name usage: int z = UseBeforeDeclaration.x * 2; // ok - not accessed via simple name (In reply to comment #3) > (In reply to comment #2) > > Checking > > http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.3.2.3 it > > appears that qualified references are accepted. > > Only simple references are rejected. > > Isn't there a bug even in the JLS? > The first sentence states that checking for this particular problem is > only performed if all four requirements are met. Thus if any of the four > requirements is not met we're good without checking textual order. > > The next sentence says: > "A compile-time error occurs if any of the four requirements above are not > met." > which to me sounds like a contradiction. > > Should we silently ignore that sentence? I agree that the last sentence does sound contradictory and yes IMO it is completely superfluous and should be ignored. The right interpretation is clear from examples and such.
Verified for 3.6RC4