expected body of lambda expressioncc
时间: 2024-01-27 14:05:53 浏览: 133
Figure of expected result
The body of a lambda expression is a single expression or a block of statements enclosed in curly braces. The expected body of a lambda expression depends on the functional interface it is implementing.
For a functional interface that takes no arguments and returns a value, the body would contain a single expression that evaluates to the return value. For example:
```
Supplier<String> supplier = () -> "Hello World";
```
For a functional interface that takes one or more arguments and returns a value, the body would contain a block of statements that use the arguments and return a value. For example:
```
Function<Integer, String> converter = (num) -> {
String result = "";
if (num % 2 == 0) {
result = "even";
} else {
result = "odd";
}
return result;
};
```
In general, the body of a lambda expression should be concise and readable, and should not contain any unnecessary code or side effects.
阅读全文