I'm trying to use the Java 8 Stream API mapToDouble method like so:
BigDecimal totalCost = order.getOrderlineList().stream()
.mapToDouble(Orderline::getPrice)
.sum();
The problem is that Orderline::getPrice
returns a BigDecimal
, not a Double
. Hence the attempt above fails to compile (Bad return type in method reference: cannot convert java.math.BigDecimal to doubele).
Seeing that Orderline#price
is a BigDecimal
, how can I use the Stream API (and either mapToDouble
or something similar) to get my totalCost
?