Lambda 表达式
基本语法: ([参数1,参数2...]) -> {方法的具体实现}
注意事项 :
1.传递参数可有可无,视具体方法而定。
2.方法若无返回,{} 可省略。
3.表达式外部变量,方法可以引用,并自动添加 final 修饰符
函数式接口@FunctionalInterface
注意事项 :
1.一旦接口用注解@FunctionalInterface,接口必须有抽象方法,有且只有一个
2.default 修饰符,接口支持默认方法
3.static 修饰符,接口支持静态方法
4.可以重写Object的方法
@FunctionalInterface
public interface CustomFuntionInterface {
/**
* 自定义函数方法
* @param value
*/
void customFunctionMenthod(String value);
@Override
public String toString();
/**
* 静态方法
*/
static void staticMethod(){
System.out.println("CustomFuntionInterface.staticMethod");
}
static void staticMethod2(){
System.out.println("CustomFuntionInterface.staticMethod2");
}
/**
* default修饰符 接口支持默认方法
*/
default void defaultMethod(){
System.out.println("CustomFuntionInterface.defaultMethod");
}
/**
* default修饰符 接口支持默认方法
*/
default void defaultMethod2(){
System.out.println("CustomFuntionInterface.defaultMethod2");
}
}