Lamda is an expression introduced in JAVA8 for functional programming;
The Lamda form is similar to the anonymous inner class, which can be understood as the simplification or variation of the anonymous inner class (fog);
There are several common expressions in Java:
ImportJava.util.function.BinaryOperator; Public classLamdastyle { Public Static voidMain (string[] args) {//1. No parameter type, use parentheses insteadRunnable noarguments = (), System.err.println ("Hello World");//2. No parameter multiple code block type, can be enclosed in curly bracesRunnable multistatement = (){System.err.println ("Hello"); System.err.println ("World");};//3. One parameter, you can omit the parentheses of the argumentLamdainterface oneargument = GreetingSystem.err.println (greeting);//4. Multiple Parametersbinaryoperator<integer> add = (x, y)-x+y;//5. Declaring parameter Typesbinaryoperator<integer> addexplicit = (integer x, integer y), x+y;}}Interfacelamdainterface{voidsay (String greeting);}
View Code
The above mentioned is the common form of 5 in LAMDA;
In an anonymous inner class, if you need to reference an object that is defined externally, you must declare the object as the final type, and in Lamda, the declaration is not required, but the compiler handles the referenced object as the final type, that is, the object's reference is not allowed; The LAMDA expression refers to a value, not a variable;
Reference: "Java8 functional Programming"
Copy lyrics: Think I such excellent person, should have splendid life, how more than 20 years in the end, still in the sea of drowning
Introduction to Lamda Expressions in Java8