首页 > 其他 > 详细

Lambda表达式

时间:2020-03-03 17:55:00      阅读:57      评论:0      收藏:0      [点我收藏+]
package threadtest;

import java.util.Comparator;

import org.junit.Test;

public class Lambda {
    @Test
    public void test() {
    Runnable r1=new Runnable() {
        
        @Override
        public void run() {
            System.out.println("我爱祖国");
            
        }
    };
        r1.run();
        //Lambda表达式
        Runnable r2=()->System.out.println("爱我中华");
        Runnable r21=()->{
            System.out.println("爱我老师");
            };
        r2.run();
        r21.run();
    }
    
    @Test
    public void test2() {
        Comparator<Integer> COM1=new Comparator<Integer>() {
            
            @Override
            public int compare(Integer o1, Integer o2) {
                // TODO Auto-generated method stub
                return Integer.compare(o1, o2);
            }
        };
        System.out.println(COM1.compare(111, 158));
        
        //Lambda表达式
        Comparator<Integer> COM=(o1, o2)->Integer.compare(o1, o2);{
            System.out.println(COM.compare(11, 158));
        };
        //方法引用
        Comparator<Integer> COM3=Integer::compare;
            System.out.println(COM.compare(1111, 158));
    }
}

 

Lambda表达式

原文:https://www.cnblogs.com/ylblikestudyJava/p/12403537.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!