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.Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this stream.
|
forEach, iterator, spliterator
@DischargesObligation void close() throws Exception
close
in interface AutoCloseable
Exception
Copyright © 2012–2014 Schlichtherle IT Services. All rights reserved.