-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample1.java
More file actions
47 lines (39 loc) · 957 Bytes
/
Example1.java
File metadata and controls
47 lines (39 loc) · 957 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
41
42
43
44
45
46
47
package lambda_expressions;
/*
* Example demonstrating concrete class implementation, anonymous class implementation and
* lambda expression implementation of a Functional interface.
*/
@FunctionalInterface
interface Interf{
int sum(int a, int b);
}
class InterfImpl implements Interf{
@Override
public int sum(int a, int b) {
return a+b;
}
}
public class Example1 {
public static void main(String[] args) {
//using implementation class
Interf i1 = new InterfImpl();
System.out.println(i1.sum(10,20));
//using anonymous inner class
Interf i2 = new Interf() {
@Override
public int sum(int a, int b) {
return a+b;
}
};
System.out.println(i2.sum(30,40));
//using lambda expression
Interf i3 = (a, b) -> a+b;
System.out.println(i3.sum(50,60));
}
}
/*
* Output:
* 30
* 70
* 110
*/