Created
September 11, 2018 10:08
-
-
Save orionll/f29cf8788bb735a8ac4aca25edcb0cf4 to your computer and use it in GitHub Desktop.
Bug in Array Iterator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class ArrayIterator<A> implements Iterator<A> { | |
private int i; | |
private final A[] array; | |
ArrayIterator(final A[] array) { | |
this.array = array; | |
} | |
@Override | |
public boolean hasNext() { | |
return (i < array.length); | |
} | |
@Override | |
public A next() { | |
try { | |
return array[i++]; | |
} catch (IndexOutOfBoundsException e) { | |
throw new NoSuchElementException(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment