Good evening, consider the following:
public class TestEnum implements Enumeration<String> {
private Enumeration<String> files;
private TestEnum(Vector<String> files) {
this.files = files.elements();
}
public Enumeration<String> getFiles() {
return files;
}
@Override
public boolean hasMoreElements() {
return files.hasMoreElements();
}
@Override
public String nextElement() {
return files.nextElement();
}
public static void main(String[] args) {
Vector<String> vector = new Vector<>();
vector.add("1");
vector.add("2");
vector.add("3");
vector.add("4");
vector.add("5");
TestEnum obj = new TestEnum(vector);
while(obj.getFiles().hasMoreElements()) {
System.out.println(obj.getFiles().nextElement());
}
}
}
I don't understand, where is nextElement() and hasMoreElements() methods default implementation when operating whit enumeration of strings? I know that methods implementation should be created on programmers own and it have been created , but in line:
return files.nextElement();
I call the method nextElement() on "files" object that has another implementation? If method has my implementation then it should be call nextElement() indefinitely? Or I'm wrong?