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

裏面就這樣簡簡單單一個方法!泛型

相關文章
相關標籤/搜索