为什么Java 8中的功能接口有一个抽象方法? [英] Why Functional Interfaces in Java 8 have one Abstract Method?
问题描述
正如我们在Java 8中所知,引入了功能接口的概念。功能接口有一个 abstract
方法,可以使用多种默认或静态方法。
As we know in Java 8, the concept of functional interfaces are introduced. A Functional Interface has one abstract
method and several default or static methods are possible.
但为什么Functional接口只有一个抽象方法?
如果Interface有多个抽象方法,为什么这不是一个功能接口?
But why should a Functional interface have only one abstract method? If Interface has more then one abstract method, why is this not a Functional Interface?
推荐答案
为了方便Lambda函数,引入了功能界面,也称为单一抽象方法界面。由于lambda函数只能提供1方法的实现,因此功能接口必须只有一个抽象方法。有关详细信息,请在此处参阅。
The functional interface also known as Single Abstract Method Interface was introduced to facilitate Lambda functions. Since a lambda function can only provide the implementation for 1 method it is mandatory for the functional interface to have ONLY one abstract method. For more details refer here.
编辑 - >另外值得注意的是,功能界面可以在界面中具有默认实现。您可以在上面的链接中找到有关实施的更多详细信息。
Edit -> Also worth noting here is that, a functional interface can have a default implementation in the interface. You will find a lot more details on the implementation on the link above.
这篇关于为什么Java 8中的功能接口有一个抽象方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!