Suppose we have:
class Foo {
public BigDecimal field;
}
and that we have a list of Foo
instances, i.e. List<Foo> list
.
How can we calculate the sum of the values of the field
from the objects in the list in a single line?
I found examples of similar cases using streams but they handle simpler cases and do not work for this; such as calculating for List<Integer>
or when the field
is something easily "summable" (int, Integer...).