Java 8 Lambda Expressions: Difference between revisions
Jump to navigation
Jump to search
Line 11: | Line 11: | ||
A ''lambda'' expression can be thought of as an anonymous methods. As shown in the "[[#Syntax|Syntax]]" section below, a lambda expression looks a lot like a method declaration. | A ''lambda'' expression can be thought of as an anonymous methods. As shown in the "[[#Syntax|Syntax]]" section below, a lambda expression looks a lot like a method declaration. | ||
=Playground Example= | |||
<blockquote style="background-color: AliceBlue; border: solid thin LightSteelBlue;"> | |||
:https://github.com/NovaOrdis/playground/blob/master/java/java8/lambda-expression/src/main/java/io/novaordis/playground/java/java8/lambda/Main.java<br> | |||
</blockquote> | |||
=Functional Interface= | =Functional Interface= |
Revision as of 02:36, 28 November 2016
External
- Lambda Expressions Tutorial https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html
Internal
Overview
A lambda expression can be thought of as an anonymous methods. As shown in the "Syntax" section below, a lambda expression looks a lot like a method declaration.
Playground Example
Functional Interface
An interface with only one method is named functional interface
Apparently this is the type of a lambda expression, it describe the function signature.
The Type of a Lambda Expression
Elaborate here.
Syntax
A lambda expression consists in a comma-separated list of formal parameters, enclosed in parentheses, followed by the arrow token "->" followed by a body, which may be a single expression or a statement block.
(comma_separated_formal_parameter_list) -> body
Formal Parameters
The type of the parameters may be omitted.
If there is a single parameter, the enclosed parentheses may be omitted.
Body
The body may be a single expression, or a statement block.