cannot find symbol on identity operation in lambda

Arul Dhesiaseelan aruld at acm.org
Tue Nov 27 20:29:41 PST 2012


    Arrays.asList(1, 2, 3, 4, 5).stream().map(i -> i).sum();//compile error

java: cannot find symbol
  symbol:   method sum()
  location: interface java.util.stream.Stream<java.lang.Integer>


Arrays.asList(1, 2, 3, 4, 5).stream().map((IntFunction<Integer>)i ->
i).sum();//works fine with a cast on identity
Arrays.asList(1, 2, 3, 4, 5).stream().map(i -> i * 2).sum();//works fine
without a cast, but not identity

Is this expected behavior on an identity operation in a lambda and requires
explicit typing?

-Arul


More information about the lambda-dev mailing list