@FunctionalInterface注解修饰的接口A必须只有一个方法
其他普通方法可以通过::
调用自身的方法,并且返回A,这就是类似于把A的方法实现了,具体的执行逻辑就是,通过::
调用的方法。
@FunctionalInterface
public interface Bin {
void say();
}
public class B {
void endWith() {
System.out.println("endWith=====");
}
public static void main(String[] args) {
B b = new B();
Bin bin = b.get();
bin.say();
}
public Bin get() {
return this::endWith;
}
}
网友评论