我有一个文件,adapter/new/myAdapter.java
package adapter.new;
import adapter.old.Person;
import java.util.Enumeration;
import java.util.Iterator;
public class GroupAdapter implements Group {
private adapter.old.Group oldgroup;
public GroupAdapter(adapter.old.Group oldgroup) {
this.oldgroup = oldgroup;
}
@Override
public Iterable<Person> getPersons() {
return new Iterable<Person>() {
@Override
public Iterator<Person> iterator() {
return oldgroup.getPersons().asIterator();
}
};
}
}
这是我的
adapter/old/Group.java
package adapter.old;
import java.util.Enumeration;
import java.util.Vector;
public class Group {
private String number;
private String name;
private Vector<Person> persons;
public Group(String number, String name) {
this.number = number;
this.name = name
persons = new Vector<>();
}
public Enumeration<Person> getPersons() {
return persons.elements();
}
}
当我尝试编译时:
javac old/*.java new/*.java
我收到此错误:
new/GroupAdapter.java:41: error: cannot find symbol
return oldgroup.getPersons().asIterator();
^
symbol: method asIterator()
location: interface Enumeration<Person>
1 error
我究竟做错了什么?我或多或少地遵循了教程,但是我找不到错误所在。
最佳答案
asIterator方法已添加到java9中的Enumeration类。检查您使用的javac版本。
Enumeration javadoc java 8
Enumeration javadoc java 9
关于java - 找不到符号`asIterator()`,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57380516/