forked from Nabin-joshi/java_notes_and_programs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FunctionalInterface.java
55 lines (42 loc) · 1.29 KB
/
FunctionalInterface.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
50
51
52
53
54
55
@java.lang.FunctionalInterface
interface FunI{
void show(int a);
}
@java.lang.FunctionalInterface
interface newfunc{
int config(int b,int c);
}
//class Funclass implements FunI{
// @Override
// public void show() {
// System.out.println("Hello");
// }
//}
public class FunctionalInterface {
public static void main(String[] args) {
// functional interface is the interface with only one method
//lambda expression will only works with functional interface
// FunI funI = new FunI() {
// @Override
// public void show() {
// System.out.println("Hello");
// }
// };
//
// funI.show();
//this only validate with functional interface
// anonymous class ma ni use garna milxa
//lambda expression is used to reduce the code
//this is more of the arrow functions
//lambda expression will also not create a another class file hence useful
FunI funI = (a) -> {System.out.println("hello"+a);};
funI.show(40);
// java 8 feature is lambda expression
newfunc newfun = ( b, c) -> b+c;
//or we can do
// newfunc fuc = (b,c) ->{
// return b+c;
// };
System.out.println(newfun.config(40,30));
}
}