我有理解初始化发生的顺序.这是我假设的顺序:
*Once per 1. Static variable declaration 2. Static block *Once per object 3. variable declaration 4. initialization block 5. constructor
class SomethingWrongWithMe { { b=0; //no. no error here. int a = b; //Error: Cannot reference a field before it is defined. } int b = 0; }
如果我这样做,错误会消失:
class SomethingWrongWithMe { int b = 0; { b=0; int a = b; //The error is gone. } }
我不知道为什么不会有错误
b=0;