- 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.
- 國際大學生程序設計競賽中山大學內部選拔真題解(二)
- Android應用程序開發與典型案例
- 數據庫程序員面試筆試真題與解析
- Getting Started with React
- Vue.js 3.x從入門到精通(視頻教學版)
- Selenium Design Patterns and Best Practices
- Functional Programming in JavaScript
- Web Application Development with MEAN
- JavaScript+Vue+React全程實例
- Python 3破冰人工智能:從入門到實戰
- Redis Essentials
- Go并發編程實戰
- 飛槳PaddlePaddle深度學習實戰
- 一本書講透Java線程:原理與實踐
- Django 3.0入門與實踐