I think this is because the Inner class itself is not static. From a Java perspective this is an instance variable and I suppose that (1) the class loader was not intended to be traversed to internal non-static classes to search and initialize static variable objects.
But this is not an impossibility problem, look at the following example:
public class Outer { public static class Inner { Outer owner; static String constant; { constant = "foo"; } private Inner(Outer owner) { if (owner == null) { throw new NullPointerException(); } this.owner = owner; } } public Inner newInner() { return new Inner(this); } }
Even a warning, because Inner declared static.
But, on the other hand, it has a pointer to an Outer instance that can only be created through Outer , because it has only a private constructor, and its owner cannot be null. From the point of view of the programmer, it has all the limitations for a non-stationary inner class and can be used as one (except for special idioms like Outer.this ), but from the point of view of the compiler it is static and static fields will be correctly initialized when the Outer class is initialized.
(1): Pacerier explains below why this is not true.
Serge Ballesta
source share