BinaryOperator函数式接口

咱们能够看到这个接口继承了BiFunction接口,BiFunction的结构以下,有T,U,R三个泛型参数,还有一个andThen的复合方法,而在继承BiFunction的式<T,T,T>,都是同一个类别。app

在BinaryOperator中增长了两个static方法blog

写个例子:继承

BinaryOperator<Integer> addStr = (n1, n2) -> n1 + n2;
System.out.println(addStr.apply(3, 6));

BinaryOperator<Integer> bi = BinaryOperator.minBy(Comparator.naturalOrder());
System.out.println(bi.apply(2, 3));

BinaryOperator<Integer> bi2 = BinaryOperator.maxBy(Comparator.naturalOrder());
System.out.println(bi2.apply(2, 3));

输出:接口

看着差很少名字的还有DoubleBinaryOperator,IntBinaryOperator,LongBinaryOperator,可是他们都是没有继承BIFunction<T,T,T>io

里面就这样简简单单一个方法!泛型