This is the fifth day of my participation in the August More text Challenge. For details, see:August is more challenging

preface

Among the many new and useful features in Java 8 are functional interfaces. This is the first time you’ve heard this term.

The concept of functional interfaces

A Functional Interface is an Interface that has one and only one abstract method, but can have multiple non-abstract methods. Functional interfaces can be implicitly converted to lambda expressions. Java 8 functional interfaces can be lambda-friendly to existing functions.

Functional interface composition

Consists of three parts:

  • 1, a parenthesized, comma-separated formal argument that is the argument to a method in a functional interface
  • 2, an arrow symbol: ->
  • 3. Method bodies, which can be expressions or code blocks.
(parameters) -> expression or (parameters) -> {statements; }Copy the code

The functional interface to java.util.function

interface describe
BiConsumer<T,U> Represents an operation that takes two input parameters and returns no result
BiFunction<T,U,R> Represents a method that takes two input parameters and returns a result
BinaryOperator Represents an operation on two operators of the same type and returns the result of the operators of the same type
BiPredicate<T,U> Represents a Boolean method with two arguments
BooleanSupplier Represents the provider of the Boolean value result
Consumer Represents an operation that takes an input parameter and returns nothing
DoubleBinaryOperator Represents an operation on two double operators and returns a double as a result.
DoubleConsumer Represents an operation that takes a double and returns no result.
DoubleFunction Represents a method that takes a double and returns the result
DoublePredicate Represents a Boolean method with a double parameter
DoubleSupplier Represents the provider of a double value structure
DoubleToIntFunction Take a double input and return an int.
DoubleToLongFunction Take a double input and return a long
DoubleUnaryOperator Take an argument of type double and return a value of type double.
Function<T,R> Take an input parameter and return a result.
IntBinaryOperator Take two arguments of type int and return a value of type int.
IntConsumer Take an int as an input parameter and return no value.
IntFunction Take an int input parameter and return a result.
IntPredicate Take an int as an input parameter and return a Boolean result.
IntSupplier Returns an int with no arguments.
IntToDoubleFunction Take an int and return a double.
IntToLongFunction Take an int and return a long.
IntUnaryOperator Take an argument of type int and return a value of type int.
LongBinaryOperator Take two arguments of type long and return a value of type long.
LongConsumer Take an input parameter of type long and return no value.
LongFunction Take a long input parameter and return a result.
LongPredicate R takes a long input and returns a Boolean result.
LongSupplier Returns a value of type long as a result.
LongToDoubleFunction Take a long input and return a double.
LongToIntFunction Take a long input and return an int.
LongUnaryOperator Take an argument of type long and return a value of type long.
ObjDoubleConsumer Take an object and a double as input arguments and return no value.
ObjIntConsumer Take an object and an int as input arguments and return no value.
ObjLongConsumer Take an object and a long as input parameters and return no value.
Predicate Take an input parameter and return a Boolean result.
Supplier Returns a result with no arguments.
ToDoubleBiFunction<T,U> Takes two input arguments and returns a result of type double
ToDoubleFunction Take an input parameter and return a double result
ToIntBiFunction<T,U> Take two input arguments and return an int result.
ToIntFunction Take an input parameter and return an int.
ToLongBiFunction<T,U> Take two input arguments and return a long result.
ToLongFunction Take an input parameter and return a long result.
UnaryOperator Take an argument of type T and return a value of type T.

conclusion

Many classes of java.util. Function contain functional interface. Functional interface is a relatively abstract concept, which may be new to contact or understand and feel at a loss to start.

Author introduction: [little ajie] a love to tinker with the program ape, JAVA developers and enthusiasts. Public account [Java full stack architect] maintainer, welcome to pay attention to reading communication.

Well, thank you for reading, I hope you like it, if it is helpful to you, welcome to like the collection. If there are any shortcomings, please comment and correct them. See you next time.