-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemoFunctional.java
More file actions
76 lines (60 loc) · 1.71 KB
/
Copy pathDemoFunctional.java
File metadata and controls
76 lines (60 loc) · 1.71 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package java8.lambda;
import java.util.function.BiFunction;
import java.util.function.Function;
interface testInterface1{
boolean accept();
}
interface testInterface2{
boolean test();
}
interface Calculator{
int cal(int x, int y);
}
interface Cal2{
int cal(final int y);
}
interface Cal3{
int cal(int a, int b);
}
public class DemoFunctional {
public static void main(String[] args) {
// Cal3 mixVal = (int x, y) -> x + y; // 에러
Function<Integer,Integer> test = (a)-> a+1;
Integer answer = test.apply(5);
System.out.println(answer);
// BiFunction<Integer,Integer,Integer>
Cal3 ttt = new Cal3() {
@Override
public int cal(int a, int b) {
return a+b;
}
};
Cal2 running = (final int y) -> y + 1;
int x = 2;
int y = 3;
// Calculator test = (x1, x2) -> x1 + x2;
// System.out.println(test.cal(x, y));
//
// BiFunction<Integer, Integer, Integer> tt = (a, b)-> a+b;
// int answer = tt.apply(x,y);
// System.out.println(answer);
testInterface1 test1 = new testInterface1() {
@Override
public boolean accept() {
System.out.println("이게 purefunction?");
return false;
}
};
System.out.println(test1.accept());
testInterface2 test2 = () -> {
System.out.println("lambda expression");
return false;
};
testInterface2 test3 = DemoFunctional::test;
System.out.println(test3.test());
}
private static boolean test() {
System.out.println("Method reference");
return false;
}
}