关于Iterator Collection
public static void display(Iterator<Pet> it) {
while(it.hasNext()) {
Pet p = it.next();
System.out.print(p.id() + ":" + p + " ");
}
System.out.println();
}
public static void display(Collection<Pet> pets) {
for(Pet p : pets)
System.out.print(p.id() + ":" + p + " ");
System.out.println();
}
Collection<Pet>超类不是Iterator吗
乐叶 8:33:46
为何List<Pet> petList = Pets.arrayList(8);
display(petList);
把public static void display(Collection<Pet> pets)删了就不行
------解决方案--------------------Collection的定义:
public interface Collection<E>
extends Iterable<E>
Collection接口的超类是Iterable,而不是Iterator
------解决方案--------------------
------解决方案--------------------Collection接口的超类是Iterable (可迭代的)
而不是Iterator (迭代器)