T - The type of the elements in the stream.@CleanupObligation public interface Stream<T> extends Iterable<T>, AutoCloseable
close() on this stream after use,
best with a try-with-resources statement.
For example, let's assume you would have an object named container
which has a method named stream() which returns a
Stream<Object>.
Then you should use this method like this:
try (Stream<Object> stream = container.stream()) {
for (Object object : stream) {
// Use object here...
}
}
The try-with-resources statement ensures that stream gets
close()d after the for-loop, even if it terminates with an
exception.@DischargesObligation
void close()
throws Exception
close in interface AutoCloseableExceptionCopyright © 2012–2015 Schlichtherle IT Services. All rights reserved.