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

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();
}
主站蜘蛛池模板: 塔城市| 保定市| 开远市| 新绛县| 黄浦区| 长子县| 安图县| 朝阳县| 建水县| 明光市| 密山市| 凌源市| 邻水| 焦作市| 南投市| 大悟县| 天津市| 尼玛县| 社旗县| 常山县| 紫云| 达州市| 密云县| 福海县| 嘉定区| 大足县| 滦平县| 牟定县| 社会| 五大连池市| 石渠县| 且末县| 彰武县| 瓮安县| 英吉沙县| 萍乡市| 凌云县| 曲水县| 乐至县| 呼玛县| 双鸭山市|