在System类中有一段代码: 
public final static InputStream in = nullInputStream(); 
public final static PrintStream out= nullPrintStream(); 
public final static PrintStream err= nullPrintStream(); 
请问nullInputStream()是什么意思啊?那位高手能具体解释一下吗?

解决方案 »

  1.   

    其实在
    private static InputStream nullInputStream() throws NullPointerException
    方法的说明里已经告诉我们为什么这么写了,简单的说它要先被初始化成null,然后再由initializeSystemClass()
    方法初始化。
    好好研究一下下面这段英文
    /**  * 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(). */
      

  2.   

    源代码中不是有吗?
      /**
         * 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().
         */
        private static InputStream nullInputStream() throws NullPointerException {
    if (currentTimeMillis() > 0) {
        return null;
    }
    throw new NullPointerException();
        }    private static PrintStream nullPrintStream() throws NullPointerException {
    if (currentTimeMillis() > 0) {
        return null;
    }
    throw new NullPointerException();
        }
    这2个方法是要把in,out和err初始化为null