What is the Java Supplier Interface?

The Java Supplier interface of the java.util.function package is a functional interface that is often used as an assignment target for lambda expressions. The get() method is the class’s only abstract method, which takes no input and returns an output.

For more information on functional interfaces in Java click here: What is a Java Functional Interface?.
For more information on lambdas in Java click here: What are Lambdas in Java?

Supplier Interface Source Code

Supplier Interface Example

Below is an example of creating the SupplierExample class by implementing Supplier. This get() method takes no input and returns a random Integer.

Creating a Supplier Instance with Lambda Expression

Below is an example of using a lambda expression to create an instance of Supplier. This get() method takes no input and returns a random Integer.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">