throwing exceptions in Iterator subclasses
The java Iterator class is defined as follows:
Code:
public interface Iterator<E> {
boolean hasNext();
/**
* Returns the next element in the iteration.
*
* @return the next element in the iteration.
* @exception NoSuchElementException iteration has no more elements.
*/
E next();
void remove();
}
the comment for E next() states that subclasses will throw NoSuchElementException if the collection has no more elements. How can subclasses throw this exception when E next() has no throws declaration? My understanding of Java exception handling reuires a throws declaration on next(). Please help me to understand.