Tuesday, July 14, 2015

Java Lambda - DoubleBinaryOperator Functional Interface


DoubleBinaryOperator Functional Interface

We discussed BinaryOperator previously. I would highly recommend you to read about BinaryOperator before reading DoubleBinaryOperator. BinaryOperator works on any type while DoubleBinaryOperator is a specialized BinaryOperator. It operates upon two double valued operands and returns a double result.

DoubleBinaryOperator interface has a method applyAsDouble(double left, double right).

Let us use this interface for multiplication of two variables.

      DoubleBinaryOperator doubleBinOp = (left, right) -> left * right;
      double result = doubleBinOp.applyAsDouble(1.5, 1.7);
      System.out.println(result);

Output is
2.55
       

That’s all on DoubleBinaryOperator interface.

Read about important java.util.function package’s interface here. Consumer, Function, Supplier, BinaryOperator & Predicate Functional Interfaces. I have also written on High Order functions using Function functional interface.



No comments:

Post a Comment

Ads Inside Post