我有以下代码,我正在努力改进:
BigDecimal total = entity.getAssociate().stream().map(Associates::getPropertyA)
.reduce(BigDecimal.ZERO, BigDecimal::add);
total = entity.getAssociate().stream().map(Associates::getPropertyB)
.reduce(total, BigDecimal::add);
total = entity.getAssociate().stream().map(Associates::getPropertyC)
.reduce(total, BigDecimal::add);
total = entity.getAssociate().stream().map(Associates::getPropertyD)
.reduce(total, BigDecimal::add);
Run Code Online (Sandbox Code Playgroud)
它有效,但它确实有一个更好的方法来做到这一点.有人可以就此事启发我吗?