lambda匿名函数

package com.lambda.demo;

public class demo1 {


    public static void main(String arg[]) {
        //第一种常规
//        counter c = new Robot();
//        test(c);
        //第二种匿名类
//        test(new counter() {
//
//            @Override
//            public int add(int x, int y) {
//                // TODO Auto-generated method stub
//                return x+y;
//            }
//            
//        });
        
        //Lambda表达式:使用Lambda必须要有接口,并且要求接口中仅有一个抽象方法;
        //必须有上下文环境,才能推导出lambda对应的接口
        
        test(
            (x,y)->x+y
                );
        
    }
    
    
    public static void test(counter c) {
        int a = c.add(30, 40);
        
        System.out.println(a);
    }
    
}
原文地址:https://www.cnblogs.com/wuheng-123/p/13954076.html