jdk8函数式接口——Consumer介绍

函数式接口:@FunctionalInterface

自从jdk8提供了函数式接口这一新的特性,极大地精简了java开发的方式。而在jdk8之前的版本,函数仅仅只能传递参数,而不能将一个函数或者说是行为传递过去,这意味着我们在调用某个函数时,该函数所表示的执行功能已经很明确了,对于lambda表达式来说,函数的调用,是将函数的行为传递过去,真正执行的是调用时传递的行为。@FunctionalInterface注解是标识一个接口是函数式接口。那么什么样的接口是函数式接口呢?
下面是@FunctionalInterface的注释说明:

	Conceptually, a functional interface has exactly one abstract
method.  Since {
   @linkplain java.lang.reflect.Method#isDefault()
default methods} have an implementation, they are not abstract.  If
an interface declares an abstract method overriding one of the
public methods of {
   @code java.lang.Object}, that also does
<em>not</em> count toward the interface's abstract method count
since any implementation of the interface will have an
implementation from {
   @code java.lang.Object} or elsewhere.
Note that instances of functional interfaces can be created with
lambda expressions, method references, or constructor ref
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值