Java 8 BinaryOperator Example
In this blog post, I will be explaining how the Java 8 BinaryOperator functional interface works. To know more about functional interfaces, you can refer to this blog post. Edit What is BinaryOperator The BinaryOperator is a specialization of the BiFunction interface that accepts 2 arguments. However, unlike the BiFunction it accepts 2 arguments of the same data type and returns a result of the same data type. The BinaryOperator internally uses the BiFunction.apply method. BinaryOperator Interface Example with Integer data type Consider the following code snippet: BinaryOperator<Integer> additionCalculator = (a, b) -> a +b;int input1 = 6;int input2 = 5;System.out.println("Result of adding " + input1 + " and " + input2 + " is " + additionCalculator.apply(input1, input2)); Here, we have written a BinaryOperator implementation that operates on Integer data type. It accepts two integer values, adds them and returns the result. The BiFu...