- An interface that contains only one abstract method is called a functional interface.
- Objects of this interface can be created using Lambda expressions.
- We can use the @functionalinterface annotation on any FunctionalInterface to check if it is a FunctionalInterface.
1, JAVA built-in four core functional interfaces
Functional interface | The parameter types | The return type | methods |
---|---|---|---|
Consumer<T> | T | void | void accept(T t) |
Supplier<T> | There is no | T | T get() |
Function<T,R> | T | R | R apply(T t) |
Predicate<T> | T | boolean | boolean test(T t) |
2. Other functional interfaces
Functional interface | The parameter types | The return type | methods |
---|---|---|---|
BiFunction<T,U,R> | T,U | R | R apply(T t, U u) |
UnaryOperator<T> (Function subinterface) |
T | T | T apply(T t) |
BinaryOperator<T> (BiFunction subinterface) |
T,T | T | T apply(T t1, T t2) |
BiConsumer<T,U> | T,U | void | void accept(T t, U u) |
Personal website
- Gitee Pages
- Github Pages