Function functional Interface of Java8 and examples of functional Interface
This article introduces the relevant knowledge of "Function functional interface and functional interface examples of Java8". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
A functional interface (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.
Functional interfaces can support lambda amicably with existing functions.
Introduction
A functional interface is actually an abstract interface class. The functional interfaces that existed before Java 8 include the following.
Java.lang.Runnablejava.util.concurrent.Callablejava.util.Comparator
Wait a minute.
Usage
In fact, the interface class mentioned above only needs to be modified with FunctionalInterface annotations to become a functional interface in Java. For example, Callable interface definition in JDK
@ FunctionalInterfacepublic interface Callable {V call () throws Exception;}
It's that simple.
Now let's talk about the new Function interface in Java 8. Here is the definition
/ / T is the incoming parameter / / R is the return parameter @ FunctionalInterfacepublic interface Function {R apply (T t); default Function compose (Function)