In System.java, out
is instantiated by:
public final static PrintStream out = nullPrintStream();
You would expect this to return a valid PrintStream
object, except this is what the method looks like:
private static PrintStream nullPrintStream() throws NullPointerException {
if (currentTimeMillis() > 0) {
return null;
}
throw new NullPointerException();
}
This will always return null. However, calling something like System.out.println()
calls the println()
method on a valid PrintStream
object instead of throwing a null pointer exception. Can anyone explain why this works and how/where the PrintStream
object is actually being instantiated?