Java Reference
In-Depth Information
Interface
Implementation Description
Supplier<T>
Supplier of results.
Function that accepts two arguments and produces a
double -valued result.
ToDoubleBiFunction<T,U>
Function that produces a double -valued result.
ToDoubleFunction<T>
ToIntBiFunction<T,U>
Function that accepts two arguments and produces an
int -valued result.
Function that produces an int -valued result.
ToIntFunction<T>
Function that accepts two arguments and produces a
long -valued result.
ToLongBiFunction<T,U>
Function that produces a long -valued result.
ToLongFunction<T>
UnaryOperator<T>
Function operation on a single operand that produces a
result of the same type as its operand.
Utilizing functional interfaces contained within the java.util.function
package can greatly reduce the amount of code you need to write. Not only are the
functional interfaces geared toward tasks that are performed a high percentage of the
time, but they are also written using generics, allowing them to be applied in many dif-
ferent contexts. Solution 2 demonstrates such an example, whereby the Func-
tion<T,R> interface is used to implement a lambda expression that accepts a string
argument and returns a string result.
6-3. Sorting with Fewer Lines of Code
Problem
Your application contains a list of Player objects for a hockey team. You would like
to sort that list of Player s by those who scored the most goals, and you would like to
do so using terse, yet easy-to-follow code.
Note The solutions in this recipe utilize Collections and sorting. To learn more about
Collections, refer to Chapter 7 .
Search WWH ::




Custom Search