zoukankan      html  css  js  c++  java
  • Lambda表达式语法2

    package airycode_java8.nice3;
    
    import airycode_java8.nice1.Employee;
    import org.junit.Test;
    
    import java.util.Arrays;
    import java.util.Collections;
    import java.util.List;
    
    /**
     * Created by admin on 2019/1/2.
     */
    public class TestLambda {
    
        //准备数据
        List<Employee> employeeList = Arrays.asList(
                new Employee("张三",18,9999.99, Employee.Status.FREE),
                new Employee("李四",38,5555.55,Employee.Status.BUSY),
                new Employee("王五",50,6666.66,Employee.Status.VOCATION),
                new Employee("赵六",16,3333.33,Employee.Status.FREE),
                new Employee("田七",8,7777.77,Employee.Status.BUSY)
        );
    
        //
        @Test
        public void test1(){
            Collections.sort(employeeList,(e1,e2)->{
                if (e1.getAge() == e2.getAge()) {
                    return e1.getName().compareTo(e2.getName());
                } else {
                    return Integer.compare(e1.getAge(),e2.getAge());
                }
            });
    
            for (Employee employee: employeeList) {
                System.out.println(employee);
            }
    
        }
    
        @Test
        public void test2(){
            String result = strHandle("aa", (str) -> str.toUpperCase());
            System.out.println(result);
        }
    
        public String strHandle(String string,MyFunction mf){
            return mf.getValue(string);
        }
    
        @Test
        public void test3(){
            op(100L,200L,(x,y) -> x+y);
        }
    
        public void op(Long l1,Long l2,MyFunction2<Long,Long> mf){
            System.out.println(mf.getValue(l1,l2));
        }
    
    }
    
    
    
    package airycode_java8.nice3;
    
    /**
     * Created by admin on 2019/1/2.
     */
    @FunctionalInterface
    public interface MyFunction {
    
        public String getValue(String s);
    
    }
    
    
    package airycode_java8.nice3;
    
    /**
     * Created by admin on 2019/1/2.
     */
    @FunctionalInterface
    public interface MyFunction2<T,R> {
    
        public R getValue(T t1,T t2);
    
    }
    

      

  • 相关阅读:
    PHP之十六个魔术方法详解
    PHP之十六个魔术方法详解
    让Docker容器使用静态独立的外部IP(便于集群组建)
    桥接和nat模式区别
    使用 GitHub / GitLab 的 Webhooks 进行网站自动化部署
    docker gitlab
    docker gitlab安装
    docker ui管理工具
    docker 批量删除容器
    Scrapy设置代理
  • 原文地址:https://www.cnblogs.com/airycode/p/10231614.html
Copyright © 2011-2022 走看看