执行代码:
list.stream().filter(entity -> entity.getValue() != null).map(Entity::getValue).reduce(Double::sum).get())
由于数据为空,导致报错:No value present
解决办法:
list.stream().filter(entity -> entity.getValue() != null).map(Entity::getValue).reduce(Double::sum).orElse(0D))
通过orElse方法获取数据结果。