, ((x,y) -> x + y)), , .
Classes for box primitives have static methods that perform some of the arithmetic operations, although not all of them are available. Those that are present can be used with reference to a method, for example Integer::sum.
Another way is to define the function yourself and pass it to the method:
public static final BinaryOperator<Integer> SUM = Integer::sum;
...
list.reduce(SUM)
This method is a bit more concise on the site of use, but you can decide whether the advance payment is worth writing out all the functions that you need or not.
source
share