System类是如何获取out(PrintStream的.)

来源:互联网 发布:网络语草根是什么意思 编辑:程序博客网 时间:2024/06/06 23:59

开题引出我们常用的一个方法...System.out.println();

println()这个方法是PrintStream的一个方法..然后我们再来看以下源代码.

    public final static PrintStream out = nullPrintStream();

 

    private static PrintStream nullPrintStream() throws NullPointerException {
 if (currentTimeMillis() > 0) {
     return null;
 }
 throw new NullPointerException();
    }
 System 类的这个成员变量(out)返回的是一个NULL值,到底是如何获取的???

再往下看...

 

    public static void setOut(PrintStream out) {
 checkIO();
 setOut0(out);
    }

 

    private static native void setOut0(PrintStream out);// natvie关键字,表示这个setOut0方法,是调用本地的C语言方法,或者C++方法...

 根据这个来获取