There is an overload method, collect()
, in interface Stream
with the following signature:
R collect(Supplier
If the former collect
method receive a BinaryOperator
then the following example would not compile:
ArrayList list = stream.collect(ArrayList::new,
ArrayList::add,
ArrayList::addAll);
In this case the compiler could not infer the return type of the combiner
and would give a compilation error.
So if this version of collect
method was consistent with the Collector
interface then it would promote a more complex use of this version of collect
method, that was not intended.