System.out.println()的理解


println() ,这个是方法名不难理解,但它是那个类的静态方法呢?
这个问题一会再来解答。
通过查API,发现System是个类,out是System的一个静态成员(public static final PrintStream out)

因此,我们可以知道out其实是PrintStream这个类的一个引用,其实System.out.println()这句语句正真调用了PrintStream的println()这个静态方法。

我有查看了System的源码,有这样与out相关的语句。
public final static PrintStream out = nullPrintStream();


private static PrintStream nullPrintStream() throws NullPointerException {
	if (currentTimeMillis() > 0) {
	    return null;
	}
	throw new NullPointerException();
}

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

private static native void setOut0(PrintStream out);

这里有一点我不太懂,为什么为out设置PrintStream的引用调用了C或C++呢?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值