创建函数式接口:
1 //定义了一个函数式接口
2 @FunctionalInterface
3 public interface BlogTest {
4 /*
5 函数式接口:
6 概念:有且仅有一个抽象方法的接口
7 接口中任何包含其他方法(默认,静态,私有)
8 格式:
9 interface 接口名称{
10 public abstract 返回值类型 方法名称(可选参数信息);
11 其他非抽象方法内容
12 }
13 注解:@FunctionalInterface 检测接口是否是一个函数式接口
14 */
15
16 public void show();
17 }
使用函数式接口:
1 //使用函数式接口
2 class Test02{
3 //方法中的参数是函数式接口
4 public static void show1(BlogTest blogTest){
5 System.out.println("我是一个函数式接口");
6 }
7
8 public static void main(String[] args) {
9 //调用函数式接口
10 //方法的参数是一个函数式接口,所以可以传递Lambda表达式show((函数参数)
11 show1(()->{});
12 }
13 }