Iterator.forEachRemaining semantics

Arne Siegel v.a.ammodytes at googlemail.com
Sun Apr 21 09:41:22 PDT 2013


Hi,

the apidoc comment of Iterator.forEachRemaining says:

    /**
     * Performs the given action for each remaining element, in the order
     * elements occur when iterating, until all elements have been processed or
     * the action throws an exception.  Errors or runtime exceptions thrown by
     * the action are relayed to the caller.
     *
     * @implSpec
     * <p>The default implementation behaves as if:
     * <pre>{@code
     *     while (hasNext())
     *         action.accept(next());
     * }</pre>

>From this it can be deduced that the following *can* be true for any implementation:

    iterator.forEachRemaining(x -> null).hasNext() == false


What about implementations that don't satisfy this condition? Can they be considered 
correct?

Regards
Arne Siegel


More information about the lambda-dev mailing list