- Apache Spark 2.x for Java Developers
- Sourav Gulati Sumit Kumar
- 146字
- 2021-07-02 19:01:56
Functional interface
In Java 8, all the Single Abstract Method interfaces (SAM interfaces), such as java.util.Comparator, java.io.FilenameFilter, java.lang.Comparable, java.lang.Runnable, and so on, are given a new name called the Functional interface.
Functional interfaces are the interfaces that consist of the Single Abstract Method. These interfaces are the target for Lambda expressions. So in other words, Lambda expressions can only implement the interfaces that have only one abstract method. This is the other difference between Lambda and anonymous inner classes.
A new annotation type @FunctionalInterface is added in Java 8. So if an interface is annotated with @FunctionalInterface, it is not allowed to have more than one abstract method.
The following declaration will work:
@FunctionalInterface public interface Interface1 { void method1(); }
If you try to add one more abstract method to this interface, the compiler will throw an error stating - Interface1 is not a Functional Interface.
- Java語(yǔ)言程序設(shè)計(jì)
- Mastering OpenLayers 3
- MySQL數(shù)據(jù)庫(kù)管理實(shí)戰(zhàn)
- MySQL 8從入門到精通(視頻教學(xué)版)
- Hands-On Image Processing with Python
- 編程與類型系統(tǒng)
- 時(shí)空數(shù)據(jù)建模及其應(yīng)用
- 遠(yuǎn)方:兩位持續(xù)創(chuàng)業(yè)者的點(diǎn)滴思考
- 每個(gè)人的Python:數(shù)學(xué)、算法和游戲編程訓(xùn)練營(yíng)
- 前端架構(gòu)設(shè)計(jì)
- LabVIEW數(shù)據(jù)采集(第2版)
- C#程序開(kāi)發(fā)參考手冊(cè)
- Mastering MeteorJS Application Development
- Selenium WebDriver自動(dòng)化測(cè)試完全指南
- OpenStack Networking Cookbook