In java sources, Collectors.toList is defined as:
public static <T>
Collector<T, ?, List<T>> toList() {
return new CollectorImpl<>((Supplier<List<T>>) ArrayList::new, List::add,
(left, right) -> { left.addAll(right); return left; },CH_ID);
}
Corresponding CollectorImpl constructor
CollectorImpl(Supplier<A> supplier,
BiConsumer<A, T> accumulator,
BinaryOperator<A> combiner,
Set<Characteristics> characteristics) {
this(supplier, accumulator, combiner, castingIdentity(), characteristics);
}
We see List::add
as second parameter of CollectorImpl
's contructor,I am wondering how does it maps to accumulator which is of Type
BiConsumer<A,T>
since BiConsumer
consumes two parameter and List::add
consumes one paramter only. What am I missing here?