System.in,System.out,System.err既然是final static的,为什么还有setIn(),setOut(),setErr()呢?

解决方案 »

  1.   

    System.in是一个类..类中当然可以有方法了..
      

  2.   

    从我的文档看 System.in,System.out,System.err 是 static 的,但不是 final 的。
      

  3.   

    哦。我的发错了。。应该是
    System是一个类。类中当然可以有方法了属性了..
      

  4.   

    in 和out是final的
    setIn 和 setOut就是给in和out赋值。
    不过这两个方法是natvie的。
    在native里就不需要遵守java规范了
      

  5.   

    在native里就不需要遵守java规范了?
      

  6.   

    虽然这个帖子揭了,但对上面的“setIn 和 setOut就是给in和out赋值”说法不赞成。
    可以仔细看看源码
      

  7.   

    为什么不是呢?
    源码:其中setIn0 是native的
        /**
         * Reassigns the "standard" input stream.
         *
         * <p>First, if there is a security manager, its <code>checkPermission</code>
         * method is called with a <code>RuntimePermission("setIO")</code> permission
         *  to see if it's ok to reassign the "standard" input stream.
         * <p>
         *
         * @param in the new standard input stream.
         *
         * @throws SecurityException
         *        if a security manager exists and its
         *        <code>checkPermission</code> method doesn't allow
         *        reassigning of the standard input stream.
         *
         * @see SecurityManager#checkPermission
         * @see java.lang.RuntimePermission
         *
         * @since   JDK1.1
         */
        public static void setIn(InputStream in) {
    checkIO();
    setIn0(in);
        }