Java 8 DoubleSupplier Example
In this blog post, I will be explaining how the DoubleSupplier Java 8 functional interface works. To know more about functional interfaces, you can refer this blog post. Edit The DoubleSupplier interface provides a method called getAsDouble This method does not accept any arguments. It returns a Double data type. The DoubleSupplier interface is a specialization of the Supplier interface that returns a double value. To see an example of the Supplier interface, refer to this blog post. DoubleSupplier example Consider the following code snippet: public class DoubleSupplierDemo { public static void main(String[] args) { DoubleSupplier getRandom = () -> new Random().nextDouble(); System.out.println("Random number 1 = "+getRandom.getAsDouble()); System.out.println("Random number 2 = "+getRandom.getAsDouble()); }} Here, we have implemented the DoubleSupplier.getAsDouble method using a lambda expression. This getAsDouble method simple returns a ra...