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

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();
}
主站蜘蛛池模板: 宁津县| 阿克苏市| 台州市| 道孚县| 甘洛县| 甘泉县| 织金县| 若尔盖县| 泸水县| 济源市| 张家港市| 保德县| 安岳县| 盱眙县| 平凉市| 灌南县| 鸡东县| 阜平县| 永胜县| 宜川县| 遂川县| 子洲县| 梨树县| 永新县| 秦安县| 祁阳县| 巴林左旗| 洛川县| 正镶白旗| 当阳市| 密云县| 横峰县| 方城县| 安塞县| 迁安市| 襄汾县| 宜兴市| 万安县| 乌兰浩特市| 疏附县| 涞源县|