When going through the JLS 8.3.2.3 I wasn't able to understand the following code.
class Z {
static { i = j + 2; }
static int i, j;
static { j = 4; }
}
The code is resulting in the error Cannot reference a field before it is defined
But if I change the code to
class Z {
static { i = 2; }
static int i, j;
static { j = 4; }
}
The code is getting compiled. But in both the cases the variable definition is after the initialization block. What is the mystery behind this?