-
Notifications
You must be signed in to change notification settings - Fork 0
/
Example.java
48 lines (39 loc) · 1.49 KB
/
Example.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.trl.theoreticalKnowledge.lambda.parameters.a.a1;
import static java.lang.System.out;
public class Example {
public static void main(String[] args) {
// Compilation ERROR !!! If the parameter of "Lambda Expression" has a type, this parameter must be put into parenthesis.
// out.println(
// testLambda(
// "Hello",
// String str -> str.concat(" World !!!")
// )
// );
out.println(
testLambda(
"Hello",
(String str) -> str.concat(" World !!!") // Single‐line lambda body.
)
);
// Parentheses can be omitted only if there is exactly one parameter and the data type is not specified.
out.println(
testLambda(
"Hello",
str -> str.concat(" World !!!") // Single‐line lambda body.
)
);
out.println(
testLambda(
"Hello",
(str) -> str.concat(" World !!!") // Single‐line lambda body.
)
);
}
public static String testLambda(String str, SomeFunctionlInterface_1 in) {
return in.someMethod(str);
}
}
@FunctionalInterface
interface SomeFunctionlInterface_1 {
String someMethod(String str);
}