1.一个class 继承 接口
2.匿名实例化 eg:new I(){ 方法重载}
3.其他方法 返回 接口
4.Lambda 表达式 直接实例化 匿名接口 (直接写方法)
eg:
1. public class A implements Comparator(){
public int compare(Object o1,Object o2){retrun (Student)o1.getName().compareTo((Student)o2.getName())}
}
public static void main(String[] args) {
List li=new ArrayList();
li.add(new Student);
li.stream()
.sorted(Compartor)// .sorted(new A())
.collect(Collectors.toMap(Student::getId,Student::getName,(oldValue,newValue)->newValue,LinkedHashMap::new))
}
2.
li.stream
.sorted(new Comparator(){
public int compare(Object o1,Object o2){retrun (Student)o1.getName().compareTo((Student)o2.getName())}
})
3.
li.stream
.sorted(Comparator.comparing(Student::getName)) //comparing 返回 Comparator
4.
li.stream
.sorted((x,y)->{return x.getName().compareTo(y.getName());})