API question/request: Array to Stream

Remi Forax forax at univ-mlv.fr
Wed Oct 2 02:37:44 PDT 2013


On 10/02/2013 11:02 AM, Paul Sandoz wrote:
> 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).

And it's not the first time that we have the same method at two places,
by example Integer.toString(int) and String.valueOf(int).
if one call the other, as Paul said, it's more to avoid a discovery problem.

>
>
>> 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.

and Collection literals was one item of project coin that was delayed 
and moved from jdk7 to jdk8 :)

>
> Paul.

Rémi



More information about the lambda-dev mailing list