java8特性介绍之-接口函数

来源:互联网 发布:运营商云计算案例 编辑:程序博客网 时间:2024/05/16 14:12

1.函数式接口,@FunctionalInterface

1.是一个接口

2.接口里面只能有一个抽象方法


2.函数式接口可以定义默认方法

@FunctionalInterfacepublic interface DriveInte {public void onDrive(String str);default void fun() {//函数式接口定义默认方法System.out.println("fun call back...");}}

3.函数式接口可以定义静态方法

@FunctionalInterfacepublic 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));