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..
The parameter required by
toMap
isFunction<? super T,? extends K> keyMapper
, then if you treatOperationThisMonthVO::getSurgeryDate
asFunction
, is it consistent with? super T
and? extends K
Woolen cloth? I guessOperationThisMonthVO
is a subclass ofoperationInfo
instead of the parent class, so writing it like this won’t work. Can be rewritten as:Give it a try.
The simple way is to write it as a standard lambda expression first, and then optimize it according to the IDE's prompts.