Let's stop using the EOL version ...
It's been a while since I implemented Iterator, which may be the first time. When I commit, it turns red in other people's Eclipse for some reason.
Java8Iterator.java
import java.util.Iterator;
public class Java8Iterator implements Iterator<Integer> {
@Override
public boolean hasNext() {
// TODO Auto-generated method stub
return false;
}
@Override
public Integer next() {
// TODO Auto-generated method stub
return null;
}
}
Java7Iterator.java
import java.util.Iterator;
public class Java7Iterator implements Iterator<Integer> {
@Override
public boolean hasNext() {
// TODO Auto-generated method stub
return false;
}
@Override
public Integer next() {
// TODO Auto-generated method stub
return null;
}
@Override
public void remove() {
// TODO Auto-generated method stub
}
}
Can you see the difference? Java7Iterator has a remove method, and Java8Iterator does not implement the remove method. There are environments where there is no problem even if it is not implemented, and there are environments where compilation errors occur if it is not implemented.
Looking at the Java Build Path of the project, it is "JRE System Library [Java SE-1.6]". Wasn't it even Java7!
If the project settings are Java 1.6 but jre 1.8.0 is used, the code generated by Eclipse's "Add unimplemented methods" does not include the remove method. When I configured the Compatible JRE to use jre 1.6 properly, the generated code now includes a remove method.
If you check the src.zip of JDK8, the default implementation is described in the Iterator interface. If there is a default implementation, it will not be treated as an unimplemented method.
That's why you should either bury an EOL version of Java or set up a tightly compatible JRE.
Recommended Posts