How to crete a Java Iterator that throws IOException
- by Antonio
I'd like to implement an iterator that retrieves objects from disk/network.
Iterator itr = getRemoteIterator();
while(itr.hasNext()) {
Object element = itr.next();
System.out.print(element + " ");
}
However the problem is that hasNext() and next() methods of the Iterator object does not allow to throw IOException. Is there any other standard interface work around this issue?
Desired code is:
public interface RemoteIterator<E> {
boolean hasNext() throws IOException;
E next() throws IOException;
void remove();
}