Introduction to Lamda Expressions in Java8

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.