官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 东明县| 太仆寺旗| 温泉县| 黄冈市| 宜章县| 汤原县| 霍林郭勒市| 游戏| 安福县| 阳西县| 永兴县| 远安县| 临桂县| 丁青县| 托克托县| 潞西市| 政和县| 长治县| 社会| 喀喇| 嘉禾县| 沈阳市| 赤壁市| 宜黄县| 宣威市| 浮梁县| 通海县| 肥东县| 那曲县| 溧水县| 康定县| 石林| 苏尼特右旗| 清河县| 额尔古纳市| 赣州市| 察雅县| 新宁县| 克东县| 抚州市| 高青县|