Friday, July 24, 2015

Java Lambda - IntToDoubleFunction Interface

IntToDoubleFunction Functional Interface

IntToDoubleFunction interface represents a function that accepts an int valued argument and produces a double valued result. Previously we have discussed Function interface, DoubleFunction, DoubleToLongFunction. I would highly recommend you to read the above interfaces.

IntToDoubleFunction interface is int to double primitive specialization for Function interface.

applyAsDouble() method

double applyAsDouble(int value);
This method accepts int as input and returns double as result. Let us take simple example of this interface.

IntToDoubleFunction power = (val) -> Math.pow(val, 2);
System.out.println(power.applyAsDouble(10)); //Outputs 100.0

That’s all on IntToDoubleFunction 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