我试图理解这个Java Stream方法
<R> R collect(Supplier<R> supplier,
BiConsumer<R, ? super T> accumulator,
BiConsumer<R, R> combiner);
下面的代码应该给出作为结果的55把而不是0打印出来. 有人能告诉我什么是错误的,如何改变它,以打印55?
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
// Create a supplier that returns a new mutable result container, in this case an Integer accumulator.
Supplier<Integer> supplier = () -> 0;
// Create an accumulator that adds the square of the current element to the result container.
BiConsumer<Integer, Integer> accumulator = (result, element) -> result += element * element;
// Create a combiner that adds two result containers together.
BiConsumer<Integer, Integer> combiner = (result1, result2) -> result1 += result2;
// Collect the results of the reduction operation into a single Integer value.
Integer sumOfSquares = numbers.stream()
.collect(supplier, accumulator, combiner);
System.out.println(sumOfSquares); // 55