In the System.java source, the standard input, output and error streams are declared final and initialized null?

前端 未结 3 1657
梦毁少年i
梦毁少年i 2020-11-29 12:19
public final static InputStream in = null;
public final static PrintStream out = null;
public final static PrintStream err = null;

But as we very w

3条回答
  •  时光说笑
    2020-11-29 12:46

    This is done in order to prevent "hacking". These fields can be changed only by appropriate setters that call native methods

    private static native void setIn0(InputStream in);
    private static native void setOut0(PrintStream out);
    private static native void setErr0(PrintStream err);
    

    Native methods can do everything including changing final fields.

提交回复
热议问题