Files
openide/java/java-impl/resources/inspectionDescriptions/IteratorNextDoesNotThrowNoSuchElementException.html
2025-02-05 04:43:28 +00:00

26 lines
663 B
HTML

<html>
<body>
Reports implementations of <code>Iterator.next()</code>
that cannot throw <code>java.util.NoSuchElementException</code>.
<p>
Such implementations violate the contract of <code>java.util.Iterator</code>,
and may result in subtle bugs if the iterator is used in a non-standard way.
</p>
<p><b>Example:</b></p>
<pre><code>
class Numbers implements Iterator&lt;Integer&gt; {
@Override
public Integer next() { //warning
if (hasNext()) {
return generateNext();
} else {
return null; //throw NoSuchElementException instead
}
}
...
}
</code></pre>
<!-- tooltip end -->
</body>
</html>