Skip to content

Files

Latest commit

 

History

History
22 lines (14 loc) · 655 Bytes

IteratorHasNextCallsNextMethod.md

File metadata and controls

22 lines (14 loc) · 655 Bytes

Pattern: Use of next() inside hasNext() for Iterator

Issue: -

Description

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
    }
}

Further Reading