Varargs stream factory methods

Remi Forax forax at univ-mlv.fr
Sat Apr 20 13:38:28 PDT 2013


On 04/20/2013 07:02 PM, Sam Pullara wrote:
> I like the .of() idea better than overloading .stream().
>
> Sam

I agree,
'of' is already used in EnumSet for that purpose.

Rémi

>
> On Apr 20, 2013, at 8:47 AM, Brian Goetz <brian.goetz at oracle.com> wrote:
>
>> Currently we have, in Arrays:
>>
>>     public static <T> Stream<T> stream(T[] array) {
>>         return stream(array, 0, array.length);
>>     }
>>
>>     public static IntStream stream(int[] array) {
>>         return stream(array, 0, array.length);
>>     }
>>
>> etc.
>>
>> We *could* make these varargs methods, which is useful as creating ad-hoc stream literals:
>>
>>   Arrays.stream(1, 2, 4, 8).map(...)
>>
>> The downside is that we would have to lose (or rename) methods like:
>>
>>     public static IntStream stream(int[] array,
>>                                    int fromIndex, int toIndex) {
>>
>> since stream(1, 2, 3) would be ambiguous.
>>
>> Probably better, make these static factories in the various stream interfaces:
>>
>>   Stream.of("foo", "bar")
>>
>>   IntStream.of(1, 2, 4, 8)
>>



More information about the lambda-libs-spec-experts mailing list