InterviewSolution
| 1. |
What is the basic structure/syntax of a lambda expression? |
|
Answer» FunctionalInterface fi = (String name) -> { System.out.println("Hello "+name); RETURN "Hello "+name; } Lambda expression can be divided into three distinct parts as below: 1. List of Arguments/PARAMS: (String name) A list of params is PASSED in () round brackets. It can have zero or more params. Declaring the type of PARAMETER is optional and can be inferred for the context. 2. Arrow Token: -> A body can have expressions or statements. {} curly BRACES are only required when there is more than one line. In one statement, the return type is the same as the return type of the statement. In other cases, the return type is either inferred by the return keyword or void if nothing is returned. |
|