Instance initialization blocks execute in the order in which they are defined. Why, then, does the code below have errors where indicated?
public class MyTest {
public static void main(String[] args) {
Tester t = new Tester();
}
}
class Tester {
{ int x; } // Instance initializer 1
{ x = 3; } // Instance initializer 2...ERROR cannot resolve symbol 'x'
Tester() { // Constructor
x = 5; // ERROR cannot resolve symbol 'x'
}
}
I thought the compiler just forklifted the instance initializers into the beginning of the constructor. If that's the case, both of these seem like they should work?