API question/request: Array to Stream

Paul Sandoz paul.sandoz at oracle.com
Wed Oct 2 02:02:44 PDT 2013


On Oct 2, 2013, at 10:07 AM, Gernot Neppert <mcnepp02 at googlemail.com> wrote:

> Oops, I hadn't noticed there were 2 factory methods at different places
> doing exactly the same thing.
> Won't this perpetually provoke the question "Which one should I use?"
> 

In this case i think it is mostly harmless; the answer being "which ever one you prefer" (they are effectively the same thing).


> Since java.util.Arrays has such a complete set of Stream-creation methods,
> maybe one could drop Stream.of(T...) in favour of Arrays.stream(T...)?
> 

The problem with Arrays, as with other factory creation methods, is it can be often hard to find things.

So we have placed a few static factory methods on Stream itself, and Stream.of serves the duel purpose of creating a stream from an explicit enumeration of elements or from an array of elements.

Note that we have avoided adding List.of etc (as proposed by Stephen) due to time constraints but also because it is likely we can do better with collection literals.

Paul.


More information about the lambda-dev mailing list