标题
package com.dsk.list;
import java.util.Comparator;
import org.junit.Test;
interface B{
public int add(int x,int y);
}
public class TestLambda {
@Test
public void test(){
// 无参数 无返回值 () 代替 new Runnable() -> 右侧 代替方法体
Runnable r1=()->System.out.println("hello");
//(x,y) 代替(int x,int y) ,->右侧 是该方法具体 实现
B b=(x,y)->{
System.out.println(x);
System.out.println(y);
return x+y;
};
System.out.println( b.add(5, 5));
//(x,y) 代替 int compare(T o1, T o2);
Comparator<Integer> comparator=(x,y)->{
System.out.println("函数式编程接口");
return Integer.compare(x, y);
};
//调用方法
comparator.compare(5, 6);
}
}