-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLambda1.java
More file actions
64 lines (50 loc) · 1.44 KB
/
Lambda1.java
File metadata and controls
64 lines (50 loc) · 1.44 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
/**
* @author Divyam (https://github.com/DevYam)
* @created 04/09/2020 - 10:41
* @project java
*/
public class Lambda1 {
interface FuncInter1{
int operation(int a, int b);
}
interface FuncInter2{
void sayMessage(String message);
}
public static void main(String[] args) {
/**
* Normal way of implementing interfaces
*/
// FuncInter1 fi1 = new FuncInter1() {
// @Override
// public int operation(int a, int b) {
// return a+b;
// }
// };
// System.out.println(fi1.operation(10,20));
/**
* Lambda way of implementing interfaces
*/
// FuncInter1 fi2 = (a, b)->{
// return a+b;
// };
// or
FuncInter1 fi3 = (a,b)->a+b;
// or
/**
* Using method reference
*/
// FuncInter1 fi2 = Integer::sum;
// System.out.println(fi2.operation(10,20));
// ==================================================================================
/**
* Note that lambda expressions can only be used to implement functional interfaces.
*/
/**
* A functional interface in Java is an interface that contains only
* a single abstract (unimplemented) method. A functional interface can
* contain default and static methods which do have an implementation, in
* addition to the single unimplemented method.
*/
//=============================================================================
}
}