-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
14 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,13 @@ | ||
public class Example2 { | ||
public class Example3 { | ||
public static void main(String[] args) { | ||
BaseIterator it = new RemovableIterator(); | ||
BaseIterator it = new BaseIterator(); | ||
it.init(args); | ||
while (true) { | ||
// Down-cast | ||
RemovableIterator remIt = (RemovableIterator) it; | ||
if (remIt.hasNext()) { | ||
System.out.printf("Item: %s\n", remIt.next()); | ||
remIt.remove(); | ||
// Up-cast | ||
it = remIt; | ||
} else break; | ||
while (!it.hasNext()) { | ||
System.out.println(it.next()); | ||
} | ||
/* | ||
If we pass an empty array: | ||
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 | ||
*/ | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,11 @@ | ||
public class Example2 { | ||
public static void main(String[] args) { | ||
BaseIterator it = new RemovableIterator(args); | ||
while (true) { | ||
// Down-cast | ||
RemovableIterator remIt = (RemovableIterator) it; | ||
if (remIt.hasNext()) { | ||
System.out.printf("Item: %s\n", remIt.next()); | ||
remIt.remove(); | ||
// Up-cast | ||
it = remIt; | ||
} else break; | ||
RemovableIterator it = new RemovableIterator(args); | ||
while (it.hasNext()) { | ||
System.out.println(it.next()); | ||
it.remove(); | ||
} | ||
BaseIterator baseIt = it; // Up-cast | ||
System.out.println(baseIt.remainingItems()); | ||
} | ||
} |