Wednesday, July 15, 2015

Java Lambda - DoubleSupplier Functional Interface

DoubleSupplier Functional Interface

We discussed Supplier Interface previously. I would highly recommend that you read about that first before proceeding to read about DoubleSupplier. Supplier Interface can accept any type but DoubleSupplier can only accept input of double primitive type only.

DoubleSupplier is a specialized version of Supplier that returns only double valued results.


DoubleSupplier Interface Declaration
public interface DoubleSupplier
DoubleSupplier is specialized version of Supplier that returns only double valued results.


getAsDouble() method
double getAsDouble();
Returns a result of type double. We will take a simple example and return a value of pie.
DoubleSupplier doubleSupplier = () -> 22.0 / 7.0;
System.out.println(doubleSupplier.getAsDouble()); //Outputs 3.142857142857143


That’s all on DoubleSupplier interface.



No comments:

Post a Comment

Ads Inside Post