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;
};
我想將operationInfos分組,然後算數,但是爆了這個錯。我這個方法不是靜態的方法..
扔个三星炸死你2017-07-03 11:45:19
toMap
要求的參數是Function super T,? extends K> keyMapper
,那麼你把OperationThisMonthVO::getSurgeryDate
當做呢?我猜
OperationThisMonthVO是
operationInfo的子類別而不是父類,所以這樣寫不行。可以改寫成:
toMap(operationInfo -> ((OperationThisMonthVO) operationInfo).getSurgeryDate(), ...)
試試看。