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)删了就不行
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)删了就不行
解决方案 »
- 关于JTree改变节点图标的问题
- Java 给图片添加水印后没有exif信息了
- java System.out 打印数字问题 怎么打印前面有零的数字?
- 数据库查询问题
- 有谁见过这样的错.class cannot be loaded: java.lang.ExceptionInInitializerError - java.lang.ExceptionInInitializerError
- 郁闷,这段代码哪里有错?不能通过编译。
- 如何在java中做个类似图象列表的东西?
- jokerjava(冷血) 请进,对反射技术回答的加分
- 类加载的问题
- 如何在java中使用JMail类包
- java SE中线程安全的集合问题? 看看源码 有点疑问
- 为什么滚动面板不显示滚动条呢?
public interface Collection<E>
extends Iterable<E>Collection接口的超类是Iterable,而不是Iterator
petList 显然不是一个迭代器Iterator对象,所以报错。
public static void display(Iterable<Pet> iterable) {
Iterator<Pet> it = iterable.iterator();
while (it.hasNext()) {
Pet p = it.next();
System.out.print(p.id() + ":" + p + " ");
}
System.out.println();
}