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

Functional interfaces

Functional interfaces contain one—and only one—abstract method. An abstract method is one which should have a body in the implementation class if the implementation class is not abstract. It can have any number of regular methods (methods which have a body in the implementation classes), but the prerequisite of a functional interface is that the number of abstract methods must be only one. These interfaces are used hand-in-hand with Lambda expressions.

In the following code block, the demo method is inside an interface Greeting. Therefore, this interface should only have one abstract method, which is the demo method. In order to instruct other users that this is a functional interface, we annotate this interface with the @FunctionalInterface annotation.

The type of blockofCodeA will be of this functional interface type. This annotation is optional:

@FunctionalInterface
public interface Greeting {
public void demo();
}
主站蜘蛛池模板: 防城港市| 墨玉县| 布尔津县| 江陵县| 大荔县| 弋阳县| 长春市| 白银市| 安泽县| 吉水县| 乌拉特中旗| 齐河县| 肥西县| 苏尼特左旗| 呼图壁县| 静宁县| 蕉岭县| 焦作市| 古蔺县| 龙井市| 云林县| 四会市| 卓资县| 从江县| 平舆县| 吉林省| 娄底市| 昌江| 彝良县| 泰来县| 郁南县| 石柱| 滦南县| 徐水县| 武川县| 台前县| 黎平县| 雷州市| 金塔县| 正宁县| 长沙县|