java方法签名_Java 8方法签名不一致

您是正确的,合并操作的功能签名(同样适用于reduce)不需要像BinaryOperator这样的接口.

这不仅可以通过以下事实来说明:toMap收集器的mergeFunction最终将在Map.merge处接受BiFunction您也可以将这样的BiFunction转换为所需的BinaryOperator:

BiFunction

MULTIPLY_DOUBLES = (a,b) -> a.doubleValue() * b.doubleValue();

Stream s = Stream.of(42.0,0.815);

Optional n=s.reduce(MULTIPLY_DOUBLES::apply);

或完全通用:

public static Optional reduce(

Stream s,BiFunction super T,? super T,? extends T> f) {

return s.reduce(f::apply);

}

创建BinaryOperator和UnaryOperator的最有可能的原因是与这些没有这样的超级接口的这些函数的原始类型版本对称.

在这方面,方法是一致的

Stream.reduce(BinaryOperator< T)

> IntStream.reduce(IntBinaryOperator)

> DoubleStream.reduce(DoubleBinaryOperator)

> LongStream.reduce(LongBinaryOperator)

要么

> Arrays.parallelPrefix(T [] array,BinaryOperator< T> op)> Arrays.parallelPrefix(int [] array,IntBinaryOperator op)> Arrays.parallelPrefix(double [] array,DoubleBinaryOperator op)> Arrays.parallelPrefix(long [] array,LongBinaryOperator op)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值