forked from rampatra/Algorithms-and-Data-Structures-in-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLambdas.java
39 lines (32 loc) · 960 Bytes
/
Lambdas.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
package com.rampatra.java8;
import java.util.function.Consumer;
/**
* @author rampatra
* @version 21/02/2017
*/
public class Lambdas {
private int a = 1;
public void testScopeOfLambda(Consumer<String> consumer) {
consumer.accept("Lambda");
}
public static void main(String[] args) {
Lambdas l = new Lambdas();
l.testScopeOfLambda(x -> System.out.println(x));
l.testScopeOfLambda(x -> System.out.println(x + l.a));
l.a = 2;
l.testScopeOfLambda(x -> System.out.println(x + l.a));
/*for (int i = 0; i < 10; i++) {
l.testScopeOfLambda(x -> System.out.println(x + i));
}*/
/*l.testScopeOfLambda(x -> {
int a = 2;
System.out.println(x + l.a);
});*/
l.testScopeOfLambda(new Consumer<String>() {
int a = 2;
@Override
public void accept(String s) {
}
});
}
}