cannot find symbol on identity operation in lambda
Arul Dhesiaseelan
aruld at acm.org
Wed Nov 28 11:17:57 PST 2012
Yeah, another option is using reduce :-)
...stream().reduce(Integer::sum).get()
[1]
https://github.com/aruld/java-oneliners/blob/master/src/oneliners/Item2.java
On Tue, Nov 27, 2012 at 10:09 PM, Talden <talden at gmail.com> wrote:
> On Wed, Nov 28, 2012 at 6:03 PM, Brian Goetz <brian.goetz at oracle.com>wrote:
>
>> The problem is that the type of the stream returned by map() is
>> Stream<Integer>, not IntStream.
>>
>> If you wanted an IntStream, you'd want to explicitly convert to ints:
>>
>> ...stream().map(i -> (int) i).sum()
>>
>
> Would it be correct (and possibly more expressive) to use a method
> reference for the unboxing in this case?
>
> ...stream().map(Integer::intValue).sum();
>
> (I'm aware you were really illustrating why it didn't resolve to Integer
> -> int but thought it worth noting the another representation of the
> solution)
>
> --
> Aaron Scott-Boddendijk
>
More information about the lambda-dev
mailing list