Compiler collects the instance field initialization and instance initializers in textual order and places the resulting code inside any constructor that does'n begin with this(...). It places that code after the implicit/explicit call to super(...) but before any code that the programmer wrote in the constructor. The compiler complains because if the declaration of y was placed in the constructor that takes argument calling this(y) refers a variable that is not initialized yet. The resulting code is like this

Interesting, huh? It's because the act of assignment only changes things once. After that, a and b are the same value. But because assignment operations have a low priority, they usually evaluate after index operations, thuis leaving the first expression unaffected by its use. ------------------ Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide

Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120

posted Jan 02, 2002 12:23:00

0

JLS 15.13.1 does wonders for explaining these kinds of expressions:

* First, the array reference expression is evaluated. If this evaluation completes abruptly, then the array access completes abruptly for the same reason and the index expression is not evaluated. * Otherwise, the index expression is evaluated. If this evaluation completes abruptly, then the array access completes abruptly for the same reason.

Thus the evaluation of what it is inside [] can not affect to the evaluation of the array reference expression, because this has happened before. But an assingment within [] is effective to the code that is at the right of where occurs: That is why System.out.println(a[(a=b)[3]] * a[1]); prints the result of 14*1