--- old/src/java.base/share/classes/java/util/stream/Stream.java 2019-02-27 18:10:43.000000000 -0800 +++ new/src/java.base/share/classes/java/util/stream/Stream.java 2019-02-27 18:10:43.000000000 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -103,7 +103,11 @@ * computational operations which will be performed in aggregate on that source. * However, if the provided stream operations do not offer the desired * functionality, the {@link #iterator()} and {@link #spliterator()} operations - * can be used to perform a controlled traversal. + * can be used to perform a controlled traversal. Stream implements the + * {@link IterableOnce} interface, allowing a stream instance to be used + * in an enhanced-for ("for each") statement. Note that this statement implicitly + * calls the {@code iterator()} method, which consumes the stream. The stream + * thus cannot be used for any subsequent operations. * *

A stream pipeline, like the "widgets" example above, can be viewed as * a query on the stream source. Unless the source was explicitly @@ -164,7 +168,15 @@ * @see DoubleStream * @see java.util.stream */ -public interface Stream extends BaseStream> { +public interface Stream extends BaseStream>, IterableOnce { + + // Need to re-abstract spliterator() to avoid inheriting the default + // method from Iterable. + /** + * {@inheritDoc} + * @return {@inheritDoc} + */ + Spliterator spliterator(); /** * Returns a stream consisting of the elements of this stream that match