Non-static method cannot be referenced from a static context
operationInfos.stream().collect(Collectors.toMap(OperationThisMonthVO::getSurgeryDate, Function.identity(), surgeryCountMerge));
public static final BinaryOperator<OperationCountVO> surgeryCountMerge = (v1, v2) -> {
v1.setSurgeryCount(v1.getSurgeryCount() + v2.getSurgeryCount());
return v1;
};
I wanted to group operationInfos and then count them, but I got this error. My method is not a static method..
扔个三星炸死你2017-07-03 11:45:19
The parameter required by
toMap
is Function<? super T,? extends K> keyMapper
, then if you treat OperationThisMonthVO::getSurgeryDate
as Function
, is it consistent with ? super T
and ? extends K
Woolen cloth? I guess OperationThisMonthVO
is a subclass of operationInfo
instead of the parent class, so writing it like this won’t work. Can be rewritten as:
toMap(operationInfo -> ((OperationThisMonthVO) operationInfo).getSurgeryDate(), ...)
Give it a try.
高洛峰2017-07-03 11:45:19
The simple way is to write it as a standard lambda expression first, and then optimize it according to the IDE's prompts.