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

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();
}
主站蜘蛛池模板: 花莲县| 吉首市| 多伦县| 乌拉特中旗| 开江县| 丰城市| 临海市| 五大连池市| 宁波市| 东乌珠穆沁旗| 杨浦区| 诸暨市| 绥化市| 库车县| 湖北省| 盖州市| 达州市| 喀喇| 洪湖市| 新和县| 舟山市| 英吉沙县| 临桂县| 安图县| 临桂县| 景洪市| 隆子县| 乌兰察布市| 千阳县| 青龙| 出国| 宁安市| 如皋市| 莱阳市| 洛川县| 定边县| 绥江县| 江安县| 米易县| 濮阳县| 那坡县|