Why is Java 8 Stream class AutoCloseable?
问题 In Java 8, the Stream class implements AutoCloseable. This means that a stream instance should be closed explicitly. I understand why file handlers and DB connections are closeable. But why streams? 回答1: I think the current documentation/javadoc of Stream is pretty clear: Streams have a BaseStream.close() method and implement AutoCloseable, but nearly all stream instances do not actually need to be closed after use. Generally, only streams whose source is an IO channel (such as those returned