Map<Integer, OperationCountVO> collect = operationInfos.stream().collect(Collectors.groupingBy(OperationCountVO::getCityId,
Collectors.reducing(new OperationCountVO(), (OperationCountVO v1, OperationCountVO v2) -> {
v1.setSurgeryCount(v1.getSurgeryCount() + v2.getSurgeryCount());
v1.setCityId(v2.getCityId());
return v1;
})));
大概就是我想對operationInfos集合按照里面的cityId進行分組,然后cityId一樣的話,把對象的SurgeryCount加起來返回,但是現(xiàn)在 第一次的v1是null,執(zhí)行v1.setSurgeryCount(v1.getSurgeryCount() + v2.getSurgeryCount());的時候報了空指針,我哪里寫的有問題嗎?
添加回答
舉報
0/150
提交
取消