Java 之 @FunctionalInterface

本文详细解释了Java中功能性接口的概念及其注解@FunctionalInterface的使用。功能性接口是指仅有一个抽象方法的接口,允许定义静态方法和默认方法,且不计入抽象方法计数。文章还提到了此类接口如何通过lambda表达式、方法引用或构造器引用创建实例。

An informative annotation type used to indicate that an interface type declaration is intended to be a <i> functional interface </i> as defined by Java Language Specification.

Conceptually, a functional interface has exactly one abstract method. Since {@linkplain java.lang.reflect.Method#isDefault() default methods} have an inplementation, they are not abstract. If an interface decalres an abstract mehod overriding one of the public methods of {@code java.lang.Object}, that also does <em>not</em> count toward the interface's abstract method count since any implementation of the interface will have an implementation from {@code java.lang.Ojbect} or elsewhere.

<p>Note that instances of functional interfaces can be created with lambda expressions, method references,or constractor references.

<p>If a type is annotated with this annotation type, compilers are required to generate an error message unless:

<ul>

<li>the type is an interface type and not an annotation type, enum, or class.

<li>The annotated type satisfies the requirements of a functional interface

</ul>

<p>How ever, the compiler will treat any interface meeting the definition of a functional interface as a functional interface regardless of whether or not a {@code FunctionalInterface} annotation is present on the interface declaration.

功能函数定义:

概念:有且只有一个抽象方法的接口

注意:

  • 允许定义静态方法
  • 允许定义默认方法
  • 允许java.lang.Object中的public方法
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值