Take a look at private static void initializeSystemClass() - this method is called to run, it calls setOut0() , which is native . This binds the Stream where it should be.
So, although the field may look like a public static final , it's actually not, the native code changes it.
EDIT
OP asks. Then why does JLS need the nullPrintStream method?
This is due to the java compiler - it will be "inline" static final if at the time of compilation they are assigned something constant, for example null . The compiler will actually replace each link to the field with a constant.
This will break the initialization, since objects will no longer contain a reference to Stream , but to null . Assigning a thread to return a method prevents nesting.
Some may call it a dirty hack. Wrong to use Bismarck "JDK is like sausage, itβs better not to see how it is done."
source share