/** * Uses {@link #hasNext()} to try to fetch the next item and returns it * if found, otherwise it throws a {@link NoSuchElementException}. * * @return the next item in the iteration, or throws * {@link NoSuchElementException} if there's no more items to return. */ @Override public T next() { if ( !hasNext() ) { throw new NoSuchElementException(); } T result = nextObject; nextObject = null; hasFetchedNext = false; return result; }
/** * Uses {@link #hasNext()} to try to fetch the next item and returns it * if found, otherwise it throws a {@link NoSuchElementException}. * * @return the next item in the iteration, or throws * {@link NoSuchElementException} if there's no more items to return. */ @Override public T next() { if ( !hasNext() ) { throw new NoSuchElementException(); } T result = nextObject; nextObject = null; hasFetchedNext = false; return result; }