Lambda Expression Syntax
Input arguments, body and return :(input arguments)->body
Return Values:
Examples of Lambda Expression:
A lambda expression is composed of three parts.
| Argument List | Arrow Token | Body |
(int x, int y) | -> | x + y |
The body can be either a single expression or a statement block. In the expression form, the body is simply evaluated and returned. In the block form, the body is evaluated like a method body and a return statement returns control to the caller of the anonymous method.
The
break and continue keywords are illegal at the top level, but are permitted within loops. If the body produces a result, every control path must return something or throw an exception.Input arguments, body and return :(input arguments)->body
- Left hand side is input arguments
- Right hand side is logic.
- The Arrow token is the separator between the arguments and logic,
Return Values:
- Implicit return; Simple expression does not requires a return
- Explicit return: If it is complex code , we need to explicit mention a return.
Examples of Lambda Expression:
- i->i+i;//simple expression with no types declared. Here the type is inferred.
- (String s1,String s2)->s1+s2;
- (String event)->notify(a); calling notify method with input String event.
Comments
Post a Comment