首页 新闻 会员 周边

System.out.println的源代码解释

0
悬赏园豆:5 [已解决问题] 解决于 2013-03-16 23:20

查看System类可知,out是这样定义的fianl static PrintStream out = null;
为什么使用System.out.println是不会报java.lang.NullPointerException(空指针异常)

cursem的主页 cursem | 初学一级 | 园豆:146
提问于:2013-03-15 15:57
< >
分享
最佳答案
0

可以看一下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));

收获园豆:5
pangdachong | 菜鸟二级 |园豆:274 | 2013-03-15 20:05

Thanks

cursem | 园豆:146 (初学一级) | 2013-03-16 23:19
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册