You can assign to a value earlier than its declaration - you just can't read it. So this fails too:
static { System.out.println(j + 2); }
static int j;
Whereas this is fine:
static { j = 5; }
static int j;
One of the four conditions in section 8.3.2.3 for an invalid usage is:
- The usage is not on the left hand side of an assignment.
(The double-negatives in that section are making my head hurt, but I think it relevant!)
To be honest, that part of the spec is one of the worst I've seen - it's really unclear. But the upshot is that you can assign but not read :)