Following is the code from java.lang.System class (JDK version 1.6)
public final static PrintStream out = nullPrintStream(); //out is set to 'null'
private static PrintStream nullPrintStream() throws NullPointerException {
if (currentTimeMillis() > 0) {
return null;
}
throw new NullPointerException();
}
when we write System.out.println("Something"); in our code then why don't we get NullPointerException even when 'out' is set to 'null'
Anyhow out will be set via following setOut method in System class
public static void setOut(PrintStream out) {
checkIO();
setOut0(out);
}
Theyn why JLS needs nullPrintStream method ?