为何InputStream以及其他的一些流类的close方法什么都不做呢

为什么InputStream以及其他的一些流类的close方法什么都不做呢
既然close是个空方法,那么调用他释放与流相关的系统资源是怎么实现的呢?
------解决方案--------------------
你看的哪个是空方法,肯定内部都有实现的~

    /**
     * Closes this file input stream and releases any system resources
     * associated with the stream.
     *
     * <p> If this stream has an associated channel then the channel is closed
     * as well.
     *
     * @exception  IOException  if an I/O error occurs.
     *
     * @revised 1.4
     * @spec JSR-51
     */

    public void close() throws IOException {
        if (channel != null)
            channel.close();
        close0();
    }

------解决方案--------------------
引用:
Quote: 引用:

你看的哪个是空方法,肯定内部都有实现的~

    /**
     * Closes this file input stream and releases any system resources
     * associated with the stream.
     *
     * <p> If this stream has an associated channel then the channel is closed
     * as well.
     *
     * @exception  IOException  if an I/O error occurs.
     *
     * @revised 1.4
     * @spec JSR-51
     */

    public void close() throws IOException {
        if (channel != null)
            channel.close();
        close0();
    }
   
  比如那个ByteArrayInputStream  ,为什么这个close方法是空的呢    

官方文档的介绍:
public class ByteArrayInputStream
extends InputStream
A ByteArrayInputStream contains an internal buffer that contains bytes that may be read from the stream. An internal counter keeps track of the next byte to be supplied by the read method.
Closing a ByteArrayInputStream has no effect. The methods in this class can be called after the stream has been closed without generating an IOException.
应该是这个流比较特殊,红色的这句话说了,关闭它没有任何效果~

------解决方案--------------------
既然close是个空方法,那么调用他释放与流相关的系统资源是怎么实现的呢?

例如 FileInputStream 是继承至 InputStream.
InputStream is = new FileInputStream();
is.close(); // 这时调用的是FileInputStream的close(),而不是InputStream的close(),因为is是FileInputStream的实例对象,这个就是多态。

而FileInputStream里的close()是有实现的。