Как правильно написать next() метод итератора, чтобы ./gradlew :detektall не ругался?

Код:

class DateIterator(
    startDate: LocalDate,
    private val endDateInclusive: LocalDate,
    private val stepDays: Long
) : Iterator<LocalDate> {
    private var currentDate = startDate

    override fun hasNext() = currentDate <= endDateInclusive

    override fun next(): LocalDate {
        val next = currentDate

        currentDate = currentDate.plusDays(stepDays)

        return next
    }
}

./gradlew :detektall ругается:

feature/statistics/impl/utils/DateFormatter.kt:9:7: This implementation of Iterator does not correctly implement the next() method as it doesn't throw a NoSuchElementException when no elements remain in the Iterator. [IteratorNotThrowingNoSuchElementException]

Куда дописать NoSuchElementException?


Ответы (0 шт):