How to crete a Java Iterator that throws IOException

Posted by Antonio on Stack Overflow See other posts from Stack Overflow or by Antonio
Published on 2012-10-09T13:52:53Z Indexed on 2012/10/13 15:38 UTC
Read the original article Hit count: 174

Filed under:
|
|
|

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();
}

© Stack Overflow or respective owner

Related posts about java

Related posts about iterator