我是Java 8的新手,我找不到任何原始BiConsumer(IntBiConsumer等),但是有一个ToIntBiFunction,它是BiFunction的原始特化对象。还有一个与ToIntBiFunction相同的IntBinaryOperator。
BiConsumer<Integer,String> wrappedBiConsumer = (i,s) -> System.out.printf("Consume %d %s \n",i,s);
ToIntBiFunction<String,String> toIntFunction = (a,b) -> a.length()* b.length();
我很确定他们有充分的理由设计这种方式,请让我理解它。
我看不到排除背后有任何特定的原因IntBiConsumer
,@FunctionalInterface
如果需要的话,您可以轻松地实现它。我想这是对我们没有同样的原因TriFunction
或TriConsumer
接口。
不要混合IntBinaryOperator
使用ToIntBiFunction
。(int, int) -> int
前者是类型的函数,而后者是形式(T, U) -> int
。因此,后者最多可能是,(Integer, Integer) -> int
但这会导致对象内部的基元装箱,而这对执行者来说远非如此。IntBinaryOperator
,而不是将它们拆箱,这在需要更高性能时很有用(二进制int函数就是这种情况)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句