-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment_LambdaExample.java
More file actions
45 lines (40 loc) · 1.1 KB
/
Assignment_LambdaExample.java
File metadata and controls
45 lines (40 loc) · 1.1 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
import java.util.*;
class Emp2{
int salary;
String name;
Emp2(String name,int salary) {
this.name=name;
this.salary=salary;
}
@Override
public String toString(){
return ("Name : "+name+" Salary: "+salary);
}
}
// Using method reference override fn inf method:
@FunctionalInterface
interface f1{
void add();
}
public class Assignment_LambdaExample{
public void newadd(){
System.out.println("Override funtional inf or implements it using another method ref");
}
public static void main(String[] args) {
ArrayList<Object> al= new ArrayList();
al.add(new Emp2("Dha",9883));
al.add(new Emp2("vicky",983222));
al.add(new Emp2("Ramanjeya",988300));
// HashSet
Collections.sort(al,(o1,o2)->{
Emp2 i1 =(Emp2)o1;
Emp2 i2 =(Emp2)o2;
return (Integer)(i2.salary-i1.salary);
});
System.out.println(al);
//
System.out.println("Method Reference example:");
f1 f=new Assignment_LambdaExample()::newadd;
f.add();
}
}