日期:2014-05-20  浏览次数:20717 次

关于JAVA源码中System.out的问题
我看了jdk6中System.java的源码,这么定义我们经常用的out:
public   final   static   PrintStream   out   =   nullPrintStream();
然后nullPrintStream()方法如下
private   static   PrintStream   nullPrintStream()   throws   NullPointerException   {
if   (currentTimeMillis()   >   0)   {
        return   null;
}
throw   new   NullPointerException();
        }

整个方法跑完不是回复null就是抛Exception,那我们平时还怎么用的System.out.println(..)之类的方法?

------解决方案--------------------
不要100%相信你看到的
------解决方案--------------------
其实是一样的。。。你不要相信。

------解决方案--------------------
看源码总得先看注释吧,你有没有看注释?
/**
* 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().
*/