February 2014
Beginner
1248 pages
62h 25m
English
Figure 17.16 demonstrates Stream method mapToDouble (lines 119, 126 and 132), which maps objects to double values and returns a DoubleStream. In this case, we map Employee objects to their salaries so that we can calculate the sum and average. Method mapToDouble receives an object that implements the functional interface ToDoubleFunction (package java.util.function). This interface’s applyAsDouble method invokes an instance method on an object and returns a double value. Lines 119, 126 and 132 each pass to mapToDouble the Employee instance method reference Employee::getSalary, which returns the current Employee’s salary as a double. The compiler converts this method reference into an object that ...
Read now
Unlock full access