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

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();
}
主站蜘蛛池模板: 兴义市| 孟连| 西乌珠穆沁旗| 泊头市| 贞丰县| 平邑县| 阳高县| 雷波县| 根河市| 余江县| 昂仁县| 和龙市| 宣恩县| 容城县| 新民市| 衡水市| 阳朔县| 榆林市| 鸡泽县| 会东县| 石屏县| 甘德县| 绥中县| 崇州市| 从江县| 额济纳旗| 敖汉旗| 阳信县| 高雄县| 平度市| 东海县| 延边| 高尔夫| 天水市| 汝南县| 汕尾市| 汝南县| 郓城县| 灌云县| 延安市| 盱眙县|