Why is Stream<T> not an Iterable<T> ?
michael.hixson at gmail.com
Tue Mar 26 20:03:43 PDT 2013
I think the main reason is that Iterable implies reusability, whereas
Stream is something that can only be used once - more like an
Iterator. If Stream extended Iterable then existing code might be
surprised when it receives an Iterable that throws an Exception the
second time they do "for (element : iterable)".
On Tue, Mar 26, 2013 at 7:56 PM, Oliver Doepner <odoepner at gmail.com> wrote:
> I recently joined this mailing list. I am quite excited about the
> lambda functionality coming in Java 8.
> I also had the pleasure to attend Brian's "Road to Lambda" talk at JavaOne.
> Thanks for the great work.
> Today I looked at the Javadoc at
> I hope that site has recent information. I had some problems finding
> the source itself on hg.
> I probably misunderstood the (not so obvious?) links at
> Anyhow, I noticed that both of the methods of Iterable (iterator,
> forEach) are also present on Stream.
> Now I wonder why Stream<T> does not extend Iterable<T>.
> Then I searched the lambda-dev archives for threads related to Iterables.
> I did not find a discussion directly related to this. I hope I didn't
> miss anything.
> I think that it would be nice if Stream instances could be passed to
> existing APIs that take Iterable.
> Naively speaking: Why have the same methods with the same signatures
> and semantics / Javadoc on two core Java interfaces and not make one a
> subtype of the other? That feels like a pair of quack-like-a-ducks
> calling for subtyping. :^)
> Oliver Doepner
More information about the lambda-dev