[JAVA] Item 44: Favor the use of standard functional interfaces
44. Use a standard functional interface
- By using the ones provided as standard, you can increase the ease of use and benefit from the various methods already built in.
- There are 43 functional interfaces included in java.util.function.
- The core is ```UnaryOperator
``, ``
BinaryOperator
,
Predicate
,
Function
,
Six of Consumer <T>
,
Supplier <T>
``. (6)
- Each of the above six has a functional interface for handling primitive types of
int
, `` `long, and
double```. (18)
- There are 6 Functions with SrcToResultFunction (
LongToIntFunction```, etc.). There are three SrcToObjFunctions (such as
`DoubleToObjFunction```). (9)
- There are nine that take two arguments. (9)
- There is something called BooleanSupplier. (1)
- Do not use objects that box primitive types in a functional interface that does not support primitive types. Performance deteriorates.
- You need to write a functional interface yourself in the following cases.
- When you need something that is not provided as standard, such as a functional interface that takes three arguments.
- If there are features such as being commonly used and benefiting from the description, having a strongly relevant contract (** not sure **), and benefiting from the default method. (``` Comparator `` `is given as an example)
- When writing a functional interface, be sure to add @FunctionalInterface. With this, if you write it incorrectly, it will cause a compile error.
- Methods that take a functional interface as an argument should not be overridden. (Item52)