Java 8 lambda expressions and Java 8 lambda expressions
There is only one method interface. To implement this interface for a short statement, four or five lines of useless code are required, which is too troublesome. So we need lambda
No parameter ()-> println ("do something ")
There is a parameter (int x)-> println (x );
Multiple parameters (String a, String B)-> println (a + B );
When the type can be deduced by the compiler, the type (a, B)-> println (a + B) can also be omitted );
A parameter can omit not only the type but also the parentheses, for example, x-> println (x). If it contains a type, it cannot omit the parentheses.
On the left side of the arrow is the form parameter Declaration of the original interface method, and on the right side is the implementation of the method body. You can use braces to enclose more than one sentence.