JAVA8的Lambda优点

简单的Lambda表达式

import org.junit.Test;

import java.util.Comparator;

//Arbor 2022/6/24
public class TestLambda {
    //匿名内部类
    @Test
    public void test1(){
        Comparator<Integer> com = new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return Integer.compare(o1,o2);
            }
        };
    }

	//Lambda表达式
    @Test
    public void test2(){
        Comparator<Integer> com = (x,y) -> Integer.compare(x,y);
    }
}

方法一

策略设计模式+外部接口实现类

方法二

策略设计模式+匿名内部类

方法三

策略设计模式+Lambda表达式

方式四

Lambda表达式+Steam API

posted @ 2022-06-24 11:04  Arborblog  阅读(20)  评论(0编辑  收藏  举报