Pattern: Use of next()
inside hasNext()
for Iterator
Issue: -
Verifies implementations of the Iterator interface. The hasNext()
method of an Iterator implementation should not have any side effects. This rule reports implementations that call the next()
method of the Iterator inside the hasNext()
method.
Example of incorrect code:
class MyIterator : Iterator<String> {
override fun hasNext(): Boolean {
return next() != null
}
}