java FI BinaryOperator
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java FI BinaryOperator相关的知识,希望对你有一定的参考价值。
public void testIntMethods() {
BinaryOperator<Integer> sum1 = Integer::sum;
IntBinaryOperator sum2 = Integer::sum;
BinaryOperator<Integer> max1 = Integer::max;
IntBinaryOperator max2 = Integer::max;
BinaryOperator<Integer> min1 = Integer::min;
IntBinaryOperator min2 = Integer::min;
Comparator<Integer> cmp = Integer::compare;
int[] numbers = { -1, 0, 1, 100, Integer.MAX_VALUE, Integer.MIN_VALUE };
for (int i : numbers) {
for (int j : numbers) {
assertEquals(i+j, (int) sum1.apply(i, j));
assertEquals(i+j, sum2.applyAsInt(i, j));
assertEquals(Math.max(i,j), (int) max1.apply(i, j));
assertEquals(Math.max(i,j), max2.applyAsInt(i, j));
assertEquals(Math.min(i,j), (int) min1.apply(i, j));
assertEquals(Math.min(i,j), min2.applyAsInt(i, j));
assertEquals(((Integer) i).compareTo(j), cmp.compare(i, j));
}
}
}
以上是关于java FI BinaryOperator的主要内容,如果未能解决你的问题,请参考以下文章
BinaryOperator函数式接口
Java8中Stream的归约与收集
如何在 LLVM 中提取 Icmp inst 或 binaryOperator Inst 的目标位置?
Java 8 函数式编程
Java 8 函数式编程
stream — 归约与收集