黑马程序员技术交流社区

标题: 关于System.out的一点疑惑纠结了一天了 [打印本页]

作者: 泮和顺    时间: 2012-3-10 19:40
标题: 关于System.out的一点疑惑纠结了一天了
System.out   是这样的public static final PrintStream out  既然是静态加final的 都可以说是不好改了吧  但是Systrm偏setOut(PrintStream out) 这样的方法,硬生生的可以吧输出流终端改掉了,纠结了

作者: 冯旭君    时间: 2012-3-10 20:36
System.out中out是一个静态常量,是System类中的field,所以无须new就可以直接使用,主要用来输出的,静态常量肯定是不能改变的了。而类System类中的setOut()方法,是用来重新分配“标准”的输出流的。调用此方法,首先如果有安全的管理器,用RuntimePermission("setIO") 权限调用它的checkPermission方法来查看是否可以再分配“标准”的输出流。


setOut
public static void setOut(PrintStream out)
Reassigns the "standard" output stream.
First, if there is a security manager, its checkPermission method is called with a RuntimePermission("setIO") permission to see if it's ok to reassign the "standard" output stream.


Parameters:
out - the new standard output stream

作者: 泮和顺    时间: 2012-3-10 20:43
写的不错这个 但是还是不怎么懂 钻牛角了。。。





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2