mini_Muke
2015-08-19 18:06
public List<Course> courses; //只能存放Course类型的对象
public TestGeneric(){
this.courses = new ArrayList<Course>();
}
public void testIterator(){
Iterator it = courses.iterator();
}
为什么泛型不能使用迭代器来遍历集合中元素呢?总会提示:Cannot convert from Iterator<Course>to HTMLDocument.iterator;还不能用Iterator<Course>这种方法来标注类型。
可以使用泛型进行迭代的
你的包是不是导成import javax.swing.text.html.HTMLDocument.Iterator这个了;
正确的是import java.util.Iterator;
导包有没有问题啊?
Java入门第三季
409776 学习 · 4546 问题
相似问题