java-ee - JAVA Non-static method cannot be referenced
怪我咯
怪我咯 2017-07-03 11:43:19
0
2
1194

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..

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(2)
扔个三星炸死你

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.

小葫芦

The simple way is to write it as a standard lambda expression first, and then optimize it according to the IDE's prompts.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template