进阶day06-自定义函数式接口

This commit is contained in:
2026-03-10 15:26:31 +08:00
parent 36aaf90ebe
commit e0e87886c0
2 changed files with 20 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
package com.inmind.functional_interface02;
/*
学习的内容:函数式接口的概念
函数式接口在Java中是指有且仅有一个抽象方法的接口。(今后自定义的主要的情况)
函数式接口:有且仅有一个必须被重写的抽象方法的接口.
注意:在java使用一个注解@FunctionalInterface来验证指定的接口是否是函数式接口
扩展:为何在一个接口中某些抽象方法不需要被重写??比如Comparator接口
在一个类中如果单继承和多实现,单继承的方法优先级高于接口中的方法定义,导致父类方法中
如果有跟接口中重名的方法实现的话,那么就相当于在子类中默认重写了接口的方法
*/
public class Demo04 {
}

View File

@@ -0,0 +1,6 @@
package com.inmind.functional_interface02;
@FunctionalInterface
public interface MyInterface {
int getSum(int a,int b);
}