1.函数式接口,@FunctionalInterface
1.是一个接口
2.接口里面只能有一个抽象方法
2.函数式接口可以定义默认方法
@FunctionalInterface
public interface DriveInte {
public void onDrive(String str);
default void fun() { //函数式接口定义默认方法
System.out.println("fun call back...");
}
}
3.函数式接口可以定义静态方法
@FunctionalInterface
public interface DriveInte {
public void onDrive(String str);
default void fun() { //函数式接口可以定义默认方法
System.out.println("fun call back...");
}
static void func() { //静态实现方法
System.out.println("static fun call back...");
}
}
4.Lambda表达式,匿名函数,基于数学lambda演算而来
(参数...) -> 表达式主体
Lambda表达式返回值是接口函数
完整形势如下
接口函数 = (参数...) -> 表达式主题
5.Lambda表达式迭代特性
List<String> list = new ArrayList<String>();
list.add("aa");
list.add("bb");
list.forEach(aa -> System.out.println(aa));