From e13be0a36b80209b7f11b0c981efac41266f9b53 Mon Sep 17 00:00:00 2001 From: bingor Date: Mon, 17 Oct 2022 19:07:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9D=A6=E5=85=8B=E5=A4=A7=E6=88=98=EF=BC=88?= =?UTF-8?q?=E4=B8=80=E6=9C=9F=EF=BC=89-=E8=AE=BE=E8=AE=A1=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F-Iterator=E8=BF=AD=E4=BB=A3=E5=99=A8-=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=B3=9B=E5=9E=8B1.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/msb/iterator/v4/Main.java | 3 ++- src/main/java/com/msb/iterator/v5/Main.java | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/msb/iterator/v4/Main.java b/src/main/java/com/msb/iterator/v4/Main.java index 9db4aa0..ee6ed35 100644 --- a/src/main/java/com/msb/iterator/v4/Main.java +++ b/src/main/java/com/msb/iterator/v4/Main.java @@ -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); } } } diff --git a/src/main/java/com/msb/iterator/v5/Main.java b/src/main/java/com/msb/iterator/v5/Main.java index 67122d4..cde67e9 100644 --- a/src/main/java/com/msb/iterator/v5/Main.java +++ b/src/main/java/com/msb/iterator/v5/Main.java @@ -16,14 +16,15 @@ import com.msb.iterator.v4.Dog; */ public class Main { public static void main(String[] args) { - Collection_ list = new LinkedList_(); + Collection_ list = new LinkedList_(); for (int i=0; i<15; i++) { list.add(new Dog(i)); } - Iterator_ iterator = list.iterator(); + Iterator_ iterator = list.iterator(); while (iterator.hashNext()) { - System.out.println(iterator.next()); + Dog dog = iterator.next(); + System.out.println(dog); } } }