函数式接口

当接口中 只有一个抽象方法的时候  可以用@FunctionalInterface 注解声明为函数式接口

凡是声明为函数式接口的接口 都可以用lambda表达式来处理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package atestdemo;

import java.util.*;

public class Test {

public static void main(String[] args) {

//用lambda表达式传参+函数式接口
test(()->System.out.println("当...刀卷刃了"));
test(()->System.out.println("刷...斩钢碎石"));
test(()->System.out.println("不灵不灵...一刀999"));


}

static void test(刀 dao){
System.out.println("准备............");
dao.cut();
System.out.println("结束............");
}


}

@FunctionalInterface
interface 刀{
void cut();
}