• 100执行%
    2019-11-02
    main方法没写调用close方法 为啥程序调用了close方法

    作者回复:
    这整个一节就是讲这个的。这是try-with-resource这个新语法的功能。

    
    
  • 消融
    2019-08-19
    public static OutputStream nullOutputStream() {
            return new OutputStream() {
                private volatile boolean closed;

                private void ensureOpen() throws IOException {
                    if (closed) {
                        throw new IOException("Stream closed");
                    }
                }

                @Override
                public void write(int b) throws IOException {
                    ensureOpen();
                }

                @Override
                public void write(byte b[], int off, int len) throws IOException {
                    Objects.checkFromIndexSize(off, len, b.length);
                    ensureOpen();
                }

                @Override
                public void close() {
                    closed = true;
                }老师close方法里没有回收资源啊只是返回true,真的回收在哪里啊?

            };
        }
    展开

    作者回复:
    不确定你这个代码哪儿来的,但是看方法名的话,这是nullOutputStream,应该是某些特殊的情况下使用的。

    
    
我们在线,来聊聊吧