incompatible types - found java.util.Iterator(Lot) but expected java.util.Iterator (java.lang.String)
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());
}
精彩评论