3 ms·
Today, you can write this: while (iterator.hasNext()) System.out.println(iterator.next()); Take away unchecked exceptions and iterator.next()'s NoSuch
by michaelt 6y ago
Today, you can write this:
while (iterator.hasNext())
System.out.println(iterator.next());
Take away unchecked exceptions and iterator.next()'s NoSuchElementException either becomes checked (requiring handling code that's unreachable) or gets removed (hope no-one ever forgets to check hasNext)
- Spivak 6y agoDon't get me wrong this is bad, but Java projects are littered with checks for logically but not technically unreachable code. This is one of those things that should have never been done with exceptions, I'm looking at you Python, but with Maybe. Then you can either handle the None case or prove to the compiler that it's impossible.
- andoriyu 6y agoDefending unchecked exceptions with bad iterator interface design is a little weird. `next()` should return an option that you can `map` over.