The previous blog introduced Java8 's new lambda expression, and this section describes JAVA8 's functional programming, and what is the connection between the two. Please look down ~ ~ ~
How the lambda expression is represented in the Java type.
Language designers put a lot of effort into thinking about how to make existing functions to support lambda in a friendly way. The ultimate approach is to increase the concept of functional interface, a functional interface is a common interface with a method. Like this.
An interface can be implicitly converted to a lambda expression ...
Each lambda expression corresponds to a type, usually the interface type. A "functional interface" refers to an interface that contains only an abstract method, and each lambda expression of that type is matched to this abstract method.
Because the default method is not an abstract method, you can also add the default method to your functional interface ....
We can use lambda expressions as an interface type for any abstract method, and your interface meets this requirement, you only need to add @functionalinterface annotations to your interface, and the compiler will complain if it finds that you have more than one interface for the annotation.
Take a look at the following functional programming examples:
Package com.panther.dong.java8.functional;
/**
* Created by Panther on 15-8-22.
*
/public class FunctionTest {public
static void Main (string[] args) {
converter<string, integer> converter = (from)-> integer.parseint (from);
Integer integer = Converter.convert ("231");
System.out.println (integer);
}
@FunctionalInterface
Interface Converter<f, t> {
T convert (F from);
}
Run Result:
231
Note: The default and Static methods in an interface do not affect the requirements of functional interfaces and can be used arbitrarily, but common methods can only have one