The line "att2 = false" isn't an instance initializer. I believe it is, according to
JLS 8.6. What else would you call one of those non-static unlabeled blocks inside a class but outside any method or constructor?
[B]What this statement means is that the following would be illegal:
[/B]
Those are instance
variable initializers,
JLS 8.3.2.2.
But the important difference between these two cases is not so much that one uses an instance initializer and the other uses an instance variable initializer. Rather, the
The rules for this are given in
JLS 8.3.2.3.
Here's a variation on "Spidey's" original code which does
not compile, because the usage of att1 inside the instance initializer is on the
right side, and before att1 is declared.
I don't have a copy of Maughal & Rasmussen to see just how they state this, other than the single sentence quoted above. But based on that one sentence, it seems they may be in error. Unless they define what they mean by a forward reference, such that a reference on the left hand side of an assignment is never considered a forward reference. Someone with a copy of the book may want to check this and submit an erratum if there's no further clarification.
Note that
JLS 8.3.2.3 allows one other special case of an initializer containing a non-LHS reference to a field declared later:
Basically this means that the compiler finishes parsing all outer-class field declarations before it tries to parse the details of a nested class.
I have a vague recollection that some earlier versions of the JDL might have had some bugs regarding forwsard references, so if you
test on an older compiler you may get slightly different results. But for JDK 1.4.2 at least, the results I get seem to match what the JLS actually says.
[ October 18, 2003: Message edited by: Jim Yingst ]