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
当做Function
,是否符合? super T
和? extends K
呢?我猜测OperationThisMonthVO
是operationInfo
的子类而不是父类,所以这样写不行。可以改写成:
toMap(operationInfo -> ((OperationThisMonthVO) operationInfo).getSurgeryDate(), ...)
试试看。