泛型與迭代器
public?List<Course>?courses;?//只能存放Course類(lèi)型的對(duì)象
public?TestGeneric(){
this.courses?=?new?ArrayList<Course>();?
}
public?void?testIterator(){
Iterator?it?=?courses.iterator();
}
為什么泛型不能使用迭代器來(lái)遍歷集合中元素呢?總會(huì)提示:Cannot?convert?from?Iterator<Course>to?HTMLDocument.iterator;還不能用Iterator<Course>這種方法來(lái)標(biāo)注類(lèi)型。
2016-06-06
可以使用泛型進(jìn)行迭代的
2015-11-19
你的包是不是導(dǎo)成import javax.swing.text.html.HTMLDocument.Iterator這個(gè)了;
正確的是import?java.util.Iterator;
2015-11-11
導(dǎo)包有沒(méi)有問(wèn)題啊?