Java / Interface
What are the rules for writing lambda expressions in Java 8?
- A lambda expression can have 0, 1 or more parameters.
- The parameter's type can be explicitly declared or it can be inferred from the context implicitly.
- Multiple parameters are enclosed in parentheses and delimited by commas. Empty parentheses represents an empty set of parameters.
- With single parameter, if its type is inferred, it is not required to use parentheses.
- The lambda expression body can contain 0, 1 or more statements.
- If the body of lambda expression has single statement, curly parenthesis is optional and the return type of the anonymous function is the same as that of the body expression. When there is more than one statement in body than these must be enclosed in curly brackets.
More Related questions...