开发者

incompatible types - found java.util.Iterator(Lot) but expected java.util.Iterator (java.lang.String)

开发者 https://www.devze.com 2023-01-26 06:40 出处:网络
I\'m currently having a problem to iterate over a collection. When I declare the fields and constructor and try to enter my method to iterate over the collection and print out the elements, it comes u

I'm currently having a problem to iterate over a collection. When I declare the fields and constructor and try to enter my method to iterate over the collection and print out the elements, it comes up with the following error.

incompatible types - found java.util.Iterator(Lot) but expected java.util.Iterator (java.lang.String)

Here is my code.

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());
}
}


Try this

public void close ()
{
    Iterator<Lot> it = lots.iterator();
    while(it.hasNext()) {
        System.out.println(it.next());
}
0

精彩评论

暂无评论...
验证码 换一张
取 消