Package net.dv8tion.jda.api.utils
Interface ClosableIterator<T>
-
- Type Parameters:
T
- The element type
- All Superinterfaces:
java.lang.AutoCloseable
,java.util.Iterator<T>
- All Known Implementing Classes:
LockIterator
public interface ClosableIterator<T> extends java.util.Iterator<T>, java.lang.AutoCloseable
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.This closes automatically when
Iterator.hasNext()
returnsfalse
but its recommended to only be used within atry-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
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
close()
-