-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLambdaCapture.java
More file actions
40 lines (35 loc) · 970 Bytes
/
LambdaCapture.java
File metadata and controls
40 lines (35 loc) · 970 Bytes
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
package Lambda;
import java.sql.SQLOutput;
@FunctionalInterface
interface LambdaCap{
void display();
}
class UseLambda{
void callLambda(LambdaCap L){
L.display();
}
}
class Demo{
int temp = 0;
void method(){
int count = 0; // must not be modified later
LambdaCap LE =()->{
int value = 0;
System.out.println("Lambda Capture");
System.out.println("Yes, I can capture more than one statements");
System.out.println("Value: "+(++value));
System.out.println("Count: "+(count));
System.out.println("Temp: "+(++temp));
};
LE.display();
UseLambda ul = new UseLambda();
ul.callLambda(()-> System.out.println("Lambda Expression as Method Object"));
// Passing method as an Object
}
}
public class LambdaCapture {
public static void main(String[] args) {
Demo d = new Demo();
d.method();
}
}