坦克大战(一期)-设计模式-Iterator迭代器-添加泛型1.1

DesignPatterns
bingor 2 years ago
parent 5e9a629668
commit e13be0a36b

@ -21,7 +21,8 @@ public class Main {
Iterator_ iterator = list.iterator();
while (iterator.hashNext()) {
System.out.println(iterator.next());
Dog dog = (Dog) iterator.next();
System.out.println(dog);
}
}
}

@ -16,14 +16,15 @@ import com.msb.iterator.v4.Dog;
*/
public class Main {
public static void main(String[] args) {
Collection_ list = new LinkedList_();
Collection_<Dog> list = new LinkedList_();
for (int i=0; i<15; i++) {
list.add(new Dog(i));
}
Iterator_ iterator = list.iterator();
Iterator_<Dog> iterator = list.iterator();
while (iterator.hashNext()) {
System.out.println(iterator.next());
Dog dog = iterator.next();
System.out.println(dog);
}
}
}

Loading…
Cancel
Save