第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

閱源-jdk8-FunctionalInterface注解

標簽:
Java

package java.lang;import java.lang.annotation.*;/** * An informative annotation type used to indicate that an interface * type declaration is intended to be a <i>functional interface</i> as * defined by the Java Language Specification. * * Conceptually, a functional interface has exactly one abstract * method.  Since {@linkplain java.lang.reflect.Method#isDefault() * default methods} have an implementation, they are not abstract.  If * an interface declares an abstract method 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.Object} or elsewhere. * * <p>Note that instances of functional interfaces can be created with * lambda expressions, method references, or constructor 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>However, 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. * * @jls 4.3.2. The Class Object * @jls 9.8 Functional Interfaces * @jls 9.4.3 Interface Method Body * @since 1.8 */@Documented@Retention(RetentionPolicy.RUNTIME)@Target(ElementType.TYPE)public @interface FunctionalInterface {}

Conceptually, a functional interface has exactly one abstract method.
Since default methods have an implementation, they are not abstract.
If an interface declares an abstract method overriding one of the public methods of java.lang.Object, that also does not count toward the interface's abstract method count since any implementation of the interface will have an implementation from java.lang.Object or elsewhere.

打捞要点之后有这么三点:

  1. a functional interface has exactly one abstract method.

    要声明FunctionalInterface的接口只能有1个抽象方法;

  2. Since default methods have an implementation, they are not abstract.

    因为default方法有实现,所以它也不是抽象方法, 所以不在列;

  3. If an interface declares an abstract method overriding one of the public methods of java.lang.Object, that also does not count toward the interface's abstract method count since any implementation of the interface will have an implementation from java.lang.Object or elsewhere.

    因为这里限定抽象方法只能有1个,那么如果我的接口里声明了一个 抽象方法"String toString();"或者"boolean equals(Object obj);"这样的,算不算呢? --->答案是: 不算这个,因为任何实现接口的对象都会继承Object,所以这些public的Object的方法,不算在列的。

也就是说,你的接口可以声名如下:

/** * Created by niewj on 2017/10/26. */@FunctionalInterfacepublic interface FunctionalInterfaceSummary {    int doSum(int x, int y); // 抽象方法    String toString(); // 不占1的数额    boolean equals(Object obj); // 不占1的数额    // boolean equals(); // 这个会占1的数额, 因为这不是Object中的方法    default void display() {        System.out.println("show sth..");    }}

小结:

  1. 如果一个接口里只限定一个抽象方法,则可以用注解@FunctionalInterface 限定;

  2. 声明为函数式接口之后,就有以下特征:
    a.  只有一个抽象方法;
    b. Object类中的public的方法也在接口里写出来的,也可以,因为这写不算;
    c.  default方法不算, 因为它们是implementation。不是abstract!

點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優(yōu)質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優(yōu)惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號

舉報

0/150
提交
取消