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. */ @FunctionalInterface public 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!
相关推荐
npm i -g marked-toc --save 在任何降价文件中,添加<!-- toc -->要添加 TOC 的位置。 然后在命令行中,运行: toc [filename] 如果您将 toc 添加到README.md ,则无需添加[filename] ,只需运行toc 。 ...
browsermob-proxy-client.zip,Java客户端库通过其rest-apiJava客户端库独家安装、启动和控制BrowserMob代理通过其rest-api独家安装、启动和控制BrowserMob代理
const linkify = require ( "marked-linkify-it" ) ; // or ES Module script // import marked from "https://cdn.jsdelivr.net/gh/markedjs/marked/lib/marked.esm.js"; // import linkify from ...
标记形式 ... 从诸如[text ?input?](name)类的markdown链接生成标签和输入控件。 安装 npm install marked-forms 重大变化 从v3.0.0版本开始,该库使用插件api。...var markedForms = require ( 'marked-forms' )
marked-engine是兼容的模板引擎,用于呈现Markdown。 安装 $ npm install marked-engine 用法 将marked-engine注册marked-engine扩展名为“ .md”的文件的模板引擎。 app . engine ( 'md' , require ( 'marked-...
totalshare2java.zip,一种提供基于常用的OAuth2的第三个网站登录功能的工具。一种提供基于常用的OAuth2的第三个网站登录功能的工具。
这是marked的流行库的分支(从chjj / release-0.3.7,2017年12月1日合并合并请求#961)。 郎 目录 安装 npm install @ts-stack/markdown --save 用法 最少使用量: import { Marked } from '@ts-stack/markdown' ...
npm install marked marked-terminal 例子 var marked = require ( 'marked' ) ; var TerminalRenderer = require ( 'marked-terminal' ) ; marked . setOptions ( { // Define custom renderer renderer : new ...
安装npm install marked-images用法注意:重大更改: 从 ,该库使用插件api。 var marked = require ( 'marked' ) ;var markedImages = require ( 'marked-images' ) ;// opts are optionalvar opts = { xhtml : ...
hexo-renderer-marked-plus 极大地基于hexo-renderer-marked-plus ,只是在 CSS 样式冲突的情况下修改标题的 id。
涉及的步骤如下:$ git clone https://github.com/code-plus-coffee/marked-preview.git$ cd marked-preview# NPM$ npm install or npm i# OR# Yarn$ yarn# After npm install is done$ npm start 现在可以在访问...
演示版<h2>Basic marked-calendar Demo</h2><h3>Demo</h3><marked-calendar year="2020" title="Imputacion de horas" savedata weekends legend='[ {"code": "#0F0", "label": "V", "title": "Vacaciones"}, {...
var mdRenderer = require ( 'marked-to-md' ) ; var source = '# Markdown to md renderer\nHello world!' ; var tokens = marked . lexer ( source ) ; var mdToMd = parser . parse ( tokens ) ; console . log ...
安装$ npm install hexo-renderer-marked --save 十六进制4:> = 2.0 十六进制3:> = 0.2 十六进制2:0.1.x选项您可以在_config.yml配置此插件。 marked : gfm : true pedantic : false breaks : true smartLists : ...
$ npm install --save marked-sanitizer-github 用法 它输出一类SanitizeState因为该清理是有状态的。 您可以通过调用getSanitizer()方法来为标记的解析器获取一个消毒剂。 它返回一个要清除的函数对象。 con
marked, Markdown 解析器和编译器 为速度而生 标记一个全功能的Markdown 解析器和编译器,用。 为速度而生。 安装npm install marked --save用法最小用法:var marked = require('marked');con
用户宏,可通过marked.js在Confluence页面内允许GitHub风格的降价块。描述此宏旨在在页面中呈现markdown主体内容,同时在宏主体中保留原始markdown代码,以便页面的后续编辑可以更新markdown代码。 markdown代码在...