System.out is declared as static final and initialized with null? [duplicate]

It is initialized with native code in a static initializer.
At the top of System.java you have:

/* register the natives via the static initializer.
 *
 * VM will invoke the initializeSystemClass method to complete
 * the initialization for this class separated from clinit.
 * Note that to use properties set by the VM, see the constraints
 * described in the initializeSystemClass method.
 */
private static native void registerNatives();
static {
    registerNatives();
}

The registerNatives() method will initialize in/out/err – and it’s doing so in native code – native code can pretty much do whatever it want and are not limited to all of the java language rules. (Though you could get around setting an already initialized final field in Java via reflection too)

Leave a Comment