Possible JSR-310 (date/time API) stream methods

Brian Goetz brian.goetz at oracle.com
Fri Mar 8 08:04:23 PST 2013

> If a user needs an Iterable, it's not too much trouble either
>      Iterable<A> iterable = ()->source.stream().iterator();

While this satisfies the type system, it is asking for trouble.  Users 
routinely assume Iterable means "can be iterated repeatedly."  This is a 
pretty crippled Iterable.

> That should cover all legacy usages that interface with
> Iterable/Iterator. So I agree that new APIs can forget about
> Iterable/Iterator.

Still, I agree with this conclusion.  Returning Iterator/Iterable as a 
LCD is nearly always the wrong thing.

If you know the caller needs a reified aggregate, return a Collection. 
If you think the caller merely needs access to the elements, return a 
Stream, with the best Spliterator you can give it.

More information about the lambda-dev mailing list