Hi all,
I've implemented a custom java.util.Iterator using a resource that sould be released at the end using a close()
method. That resource could be a java.sql.ResultSet, a java.io.InputStream etc...
public interface CloseableIterator<T> extends Iterator<T>
{
public void close();
}
Some external libraries using this iterator might not know that it must be closed. e.g:
public boolean isEmpty(Iterable<T> myiterable)
{
return myiterable.iterator().hasNext();
}
In that case, is there a way to close this iterator ?
Many Thanks,
Pierre
update: many thanks for the current answers . I'll give a (+1) to everybody. I do already close the Iterator when hasNext() returns false. My problem is when the loop iterating breaks before the last iteration as it is shown in my example.