Functional Interface即函数式接口,在这个接口里面只能有一个抽象方法,即Single Abstract Method Interface。
@FunctionalInterface
public interface FunctionAdd
{
void add(int i);
}
You can declare a method that use FunctionAdd as the type such as
public void transform(FunctionAdd functionAdd) {
functionAdd.add();
}
transform(Add1::add);
transform(Add2::addRequired);
只要函数签名一致就可以传递,函数名本身不一定非得一样。
原文:http://blog.youkuaiyun.com/hongchangfirst/article/details/80450014
作者:hongchangfirst
hongchangfirst的主页:http://blog.youkuaiyun.com/hongchangfirst
本文深入解析函数式接口(FunctionalInterface)的概念,强调其在Java中作为SingleAbstractMethodInterface的角色,通过示例展示如何使用函数式接口进行方法声明及调用,如FunctionAdd接口的add方法。文章指出,只要函数签名一致,不同名称的方法也可以相互传递。
1614

被折叠的 条评论
为什么被折叠?



