Java 8中的功能接口是什么?
功能接口是只有一种抽象方法的接口。它们势必展现出独特的功能。Runnable,Comparable和Predicate是功能接口的一些示例。
@FunctionalInterfaceAnnotation用于确保功能接口不能具有多个抽象方法。从Java8开始,我们可以将lambda表达式分配给功能接口对象。
让我们看看用户定义的功能接口如何工作-
示例
@FunctionalInterface
interface Cube {
int compute(int x);
}
public class Example {
public static void main(String args[]) {
int p = 6;
Cube c = r -> r * r * r; // lambda expression which defines the compute method
int result = c.compute(p);
System.out.println(result);
}
}输出结果
输出如下-
216
热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短