Source of Comparator.com paring () needs to receive a Function parameter of type:
Public static & lt; T, U extends Comparable<? Super U> Comparator
Function<? Super T,? Extends U> KeyExtractor)
{
Objects. RequireNonNull (keyExtractor);
Return (Comparator
(c1, c2) - & gt; KeyExtractor. Apply (c1). CompareTo (keyExtractor. Apply (c2));
}
Why at the time when using, can be introduced to: Supplier type parameters, the following
Supplier
Apples. Sort (Comparator.com paring Apple: : getColor ());
Apple: : getColor return value types: Supplier types, i.e., they can out of the incoming comparing method, and the Function and: Supplier not implemented in the source and inheritance relationships
CodePudding user response:
There is a problemCollectors. ToList () method of source:
Public static & lt; T>
Collector
Return new CollectorImpl<> ((Supplier
- & gt;) ArrayList: : new, List: : add,
(left, right) - & gt; {left. AddAll (right); Return the left; },
CH_ID);
}
New CollectorImpl is the second parameter of the incoming List: : add
But function definition is like this:
CollectorImpl (Supplier : supplier,
BiConsumer An accumulator,
BinaryOperator Combiner,
Set
This (: supplier, accumulator, combiner, castingIdentity (), characteristics);
}
BiConsumer Accumulator, how to receive the List: : add, normally speak List: : add is a typical BiPredicate type
CodePudding user response:
I don't understand why, so also in mybatisplus LambdaQueryWrapper, they tried they not doCodePudding user response:
SupplierApples. Sort (Comparator.com paring Apple: : getColor ());
Obviously not preach entered colorStr: Supplier type