62,615
社区成员
发帖
与我相关
我的任务
分享
/ /**
* The "standard" output stream. This stream is already
* open and ready to accept output data. Typically this stream
* corresponds to display output or another output destination
* specified by the host environment or user.
* 。。。。。。。。。。。
*/
public final static PrintStream out = nullPrintStream();
private static PrintStream nullPrintStream() throws NullPointerException {
if (currentTimeMillis() > 0) {
return null;
}
throw new NullPointerException();
}
/* First thing---register the natives */
private static native void registerNatives();
static {
registerNatives();
}
/**
* 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();
}
在nullInputStream方法上面,这里提供的意思和你的一样!
十分感谢! /* register the natives via the static initializer.
*
* VM will invoke the initializeSystemClass method to complete
* the initialization for this class separated from clinit.
* Note that to use properties set by the VM, see the constraints
* described in the initializeSystemClass method.
*/
private static native void registerNatives();
static {
registerNatives();
}
JVM 会调用这个类中的 initializeSystemClass 方法,其中使用 setOut 方法会重置 out 的值。之所以初始化为 nullPrintStream 指的是在 JVM 还没有调用 initializeSystemClass 方法之前,这个 out 是不可用的。