查看System类可知,out是这样定义的fianl static PrintStream out = null;
为什么使用System.out.println是不会报java.lang.NullPointerException(空指针异常)
可以看一下nullPrintStream()函数注释:
/**
* The following two methods exist because in, out, and err must be
* initialized to null. The compiler, however, cannot be permitted to
* inline access to them, since they are later set to more sensible values
* by initializeSystemClass().
*/
在initializeSystemClass()函数中对out做了初始化。
setOut0(new PrintStream(new BufferedOutputStream(fdOut, 128), true));
Thanks