RFR 8168745 Iterator.forEachRemaining vs. Iterator.remove (original) (raw)

Paul Sandoz paul.sandoz at oracle.com
Mon Nov 21 19:20:04 UTC 2016


Hi,

Please review these specification clarifications to the methods Iterator.forEachRemaining and Iterator.remove.

Implementations of Iterator.forEachRemaining should have some wiggle room to optimize traversal. (In hindsight we could have done a better job locking such behaviour down in Java 8.)

I also took the opportunity to update the Iterable.forEach method.

Thanks, Paul.

diff -r 4bf7aaa0d611 src/java.base/share/classes/java/lang/Iterable.java --- a/src/java.base/share/classes/java/lang/Iterable.java Thu Nov 17 12:24:51 2016 -0800 +++ b/src/java.base/share/classes/java/lang/Iterable.java Mon Nov 21 10:55:21 2016 -0800 @@ -53,10 +53,12 @@ /** * Performs the given action for each element of the {@code Iterable} * until all elements have been processed or the action throws an

diff -r 4bf7aaa0d611 src/java.base/share/classes/java/util/Iterator.java --- a/src/java.base/share/classes/java/util/Iterator.java Thu Nov 17 12:24:51 2016 -0800 +++ b/src/java.base/share/classes/java/util/Iterator.java Mon Nov 21 10:55:21 2016 -0800 @@ -76,10 +76,15 @@ /** * Removes from the underlying collection the last element returned * by this iterator (optional operation). This method can be called

@@ -102,6 +107,16 @@ * have been processed or the action throws an exception. Actions are * performed in the order of iteration, if that order is specified. * Exceptions thrown by the action are relayed to the caller.



More information about the core-libs-dev mailing list