Java8 函数式接口

java.util.function 包下面有大量的函数式接口,主要分为以下几个基本类别
Function<T, R>      输入参数为类型T, 输出为类型R,         记作 T -> R
Consumer<T>         输入参数为类型T, 输出为void,          记作 T -> void
Supplier<T>         没有输入参数, 输出为类型T,            记作 void -> T
Predicate<T>        输入参数为类型T, 输出为类型boolean,   记作 T -> boolean

如果输入参数是两个,这时可以使用
BiFunction<T, U, R>         记作 <T, U> -> R
BiConsumer<T, U>            记作 <T, U> -> void
BiPredicate<T, U>           记作 <T, U> -> boolean

如果一个Function的输入参数类型和输入参数类型相同,即Function<T, T>,这时可以使用 UnaryOperator<T>
UnaryOperator<T>            记作 T -> T

如果使用BiFunction时,两个输入参数和输出参数均是同一类型,即BiFunction<T, T, T>,这时可以使用BinaryOperator<T>
BinaryOperator<T>           记作 <T, T> -> T

如果输入参数是基本类型,为了避免自动拆箱装箱,可以使用
DoubleConsumer              记作 double -> void
DoubleFunction<R>           记作 double -> R
DoublePredicate             记作 double -> boolean
DoubleSupplier              记作 void -> double

IntConsumer                 记作 int -> void
IntFunction<R>              记作 int -> R
IntPredicate                记作 int -> boolean
IntSupplier                 记作 void -> int

LongConsumer                记作 long -> void
LongFunction<R>             记作 long -> R
LongPredicate               记作 long -> boolean
LongSupplier                记作 void -> long

LongToDoubleFunction        记作 long -> double
LongToIntFunction           记作 long -> double
DoubleToLongFunction        记作 double -> long
DoubleToIntFunction         记作 double -> int
IntToLongFunction           记作 int -> long
IntToDoubleFunction         记作 int -> double

ToIntFunction<T>            记作 T -> int
ToDoubleFunction<T>         记作 T -> double
ToLongFunction<T>           记作 T -> long

ToIntBiFunction<T,U>        记作 <T,U> -> int
ToDoubleBiFunction<T,U>     记作 <T,U> -> double
ToLongBiFunction<T,U>       记作 <T,U> -> long
 
IntBinaryOperator           记作 <int, int> -> int
IntUnaryOperator            记作 int -> int
DoubleBinaryOperator        记作 <double, double> -> double
DoubleUnaryOperator         记作 double -> double
LongBinaryOperator          记作 <long, long> -> long
LongUnaryOperator           记作 long -> long

ObjDoubleConsumer<T>        记作 <T, double> -> void
ObjIntConsumer<T>           记作 <T, int> -> void
ObjLongConsumer<T>          记作 <T, long> -> void

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值