我目前在迭代集合时遇到问题。当我声明字段和构造函数并尝试输入我的方法迭代集合并打印出元素时,它会出现以下错误。
不兼容的类型 - 找到java.util.Iterator(Lot)但是期望java.util.Iterator(java.lang.String)
这是我的代码。
public class Auction
{
// The list of Lots in this auction.
private ArrayList<Lot> lots;
// The number that will be given to the next lot entered
// into this auction.
private int nextLotNumber;
/**
* Create a new auction.
*/
public Auction()
{
lots = new ArrayList<Lot>();
nextLotNumber = 1;
}
public void close ()
{
Iterator<String> it = lots.iterator();
while(it.hasNext()) {
System.out.println(it.next());
}
}
答案 0 :(得分:4)
试试这个
public void close ()
{
Iterator<Lot> it = lots.iterator();
while(it.hasNext()) {
System.out.println(it.next());
}