Closed liebig closed 2 years ago
The same applies to the LargeFile
class:
public boolean hasNext() {
try {
currentLine = reader.readLine();
} catch (Exception ex) {
currentLine = null;
ex.printStackTrace();
}
return currentLine != null;
}
public String next() {
return currentLine;
}
The iterator implementations are unfortunately not correct and can lead to errors:
According to the Iterator interface, the functions should be implemented as follows:
Therefore, hasNext should be callable any number of times without the iterator loading the next element. Only next shall return the next iterative object.