July 2018
Intermediate to advanced
266 pages
7h 11m
English
When obtaining elements from an iterator using next(), it's recommended to always call hasNext() first. Failing to validate that there's an element to retrieve will result in NoSuchElementExceptions during execution, for example:
val iterator = buildIterator { yield(1)}println(iterator.next())println(iterator.next())
This iterator can only yield one value. Because next() is being called without validating the element, an exception will be thrown:

Read now
Unlock full access