-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLambdaExpressions.java
49 lines (45 loc) · 1.51 KB
/
LambdaExpressions.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
40
41
42
43
44
45
46
47
48
49
// @FunctionalInterface
// interface A {
// void show();
// }
// @FunctionalInterface
// interface A {
// void show(int a);
// }
@FunctionalInterface
interface A {
int add(int a, int b);
}
public class LambdaExpressions {
public static void main(String[] args) {
// syntatical sugar - reducing the code
// A obj = () -> {
// System.out.println("in show");
// };
// obj.show();
// A obj = (int i) -> {
// System.out.println("in show " + i);
// };
// obj.show(89);
// A obj = i -> {
// System.out.println("in show" + i);
// };
// obj.show(89);
// lambda exp with return
A obj = (int i, int j) -> i + j;
int result = obj.add(5, 9);
System.out.println(result);
// lambda exp only works with functional interfaces
// TYPES OF INTERFACES -
// Normal - normal interface, two are more methods
// Functional - (sam) sigle abstract method,interface with only one method
// Marker - a blank inteface is caled marker, if you want totell compiler
// something , java - serization - you
// can take the object and store it into your hard drive
// example when playing a game - after restart you will load current stats,now
// game is no more ....
// deserilization this is called
// serilizables ...
// blank interfaces are called marker interfaces
}
}