The Supplier Interface is a part of the java.util.function package which has been introduced since Java 8, to implement functional programming in Java. It represents a function which does not take in any argument but produces a value of type T.
Hence this functional interface takes in only one generic namely:-
Java
- T: denotes the type of the result
1. get()
This method does not take in any argument but produces a value of type T. Syntax:T get()Returns: This method returns a value of type T. Below is the code to illustrate get() method: Program:
import java.util.function.Supplier;
public class Main {
public static void main(String args[])
{
// This function returns a random value.
Supplier<Double> randomValue = () -> Math.random();
// Print the random value using get()
System.out.println(randomValue.get());
}
}
Output:
0.5685808855697841