Package net.dv8tion.jda.api.utils
Interface ClosableIterator<T>
- Type Parameters:
T
- The element type
- All Superinterfaces:
AutoCloseable
,Iterator<T>
- All Known Implementing Classes:
LockIterator
Iterator holding a resource that must be free'd by the consumer.
Close is an idempotent function and can be performed multiple times without effects beyond first invocation.
Close is an idempotent function and can be performed multiple times without effects beyond first invocation.
This closes automatically when Iterator.hasNext()
returns false
but
its recommended to only be used within a try-with-resources
block for safety.
Example
This can handle any exceptions thrown while iterating and ensures the lock is released correctly.
try (ClosableIterator<T> it = cacheView.lockedIterator()) {
while (it.hasNext()) {
consume(it.next());
}
}
- Since:
- 4.0.0
-
Method Summary
Methods inherited from interface java.util.Iterator
forEachRemaining, hasNext, next, remove
-
Method Details
-
close
void close()- Specified by:
close
in interfaceAutoCloseable
-