Skip to content

Commit

Permalink
Update example
Browse files Browse the repository at this point in the history
  • Loading branch information
jdmota committed Nov 30, 2021
1 parent 3ef4f6f commit f3e9948
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions examples/removable-iterator/Example2.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import jatyc.lib.Requires;

public class Example2 {
public static void main(String[] args) {
RemovableIterator it = new RemovableIterator(args);
BaseIterator it = new RemovableIterator(args);
RemovableIterator remIt = (RemovableIterator) iterate(it);
System.out.printf("Left: %d\n", remIt.remainingItems());
}

public static BaseIterator iterate(@Requires("HasNext") BaseIterator it) {
while (it.hasNext()) {
System.out.println(it.next());
it.remove();
System.out.printf("Item: %s\n", it.next());
}
BaseIterator baseIt = it; // Up-cast
System.out.println(baseIt.remainingItems());
return it;
}
}

0 comments on commit f3e9948

Please sign in to comment.