inconsistency in invoking method

Zhong Yu zhong.j.yu at gmail.com
Sun Mar 3 18:46:25 PST 2013


The problem is at the beginning
    Arrays.asList(1.0).stream()
which is a boxed Stream<Double>, not the primitive DoubleStream.

Not sure what's the best way to create a DoubleStream though:
    double[] data = {1.0};
    DoubleStream stream = ?how?(data);

If you don't mind the boxed stream, you can do reduce()
    Arrays.asList(1.0).stream().map(n -> n).reduce(0.0, Double::sum);

-Zhong Yu

On Sun, Mar 3, 2013 at 4:53 PM, Venkat Subramaniam
<venkats at agiledeveloper.com> wrote:
> Greetings,
>
> Not sure if this is by intent, but the following inconsistency is confusing and would be great
> if can be resolved:
>
>     System.out.println(
>       Arrays.asList(1.0).stream().map(n -> n * 1.0).sum()
>     ); //Works fine, prints 1.0
>
> However,
>
>     System.out.println(
>       Arrays.asList(1.0).stream().map(n -> n).sum()
>     ); //error: cannot find symbol
>
> Thanks
>
> Venkat
>


More information about the lambda-dev mailing list