Supplier Interface is another Built-In Functional Interface of java.util.function package of Java 8. Supplier Interface used for assignment purposes. It has only one abstract method and doesn’t have any default or static method. Below is the get() method signature. It doesn’t accept any argument and return an object.
T get()
Primitive type specialization Supplier Interface
java.util.function package has a few more supplier interface:
- IntSupplier – Represents the Integer value and has one method getAsInt().
- LongSupplier – Represents the Long value and has one method getAsLong().
- DoubleSupplier – Represents the Double value and has one method getAsDouble().
- BooleanSupplier – Represents the Boolean value and has one method getAsBoolean().
Example for Supplier Interface using Lambda
public class SupplierExample
{
public static void main(String[] args) {
Supplier pi = () -> (22.0/7);
System.out.println(pi.get());
}
}
Output
3.142857142857143
Conclusion
In this article, we have seen about supplier interfaces and other primitive specialized interfaces.


Java 8: Introduction to Streams API
Java 8 got a brand new API called streams. it makes every developer’s life easy. Stream APIs are used to process the group of data. mostly streams are applied on collection objects but we can use stream with any group

Java 8: Consumer – Built-In Functional Interfaces
Consumer Interface is another Built-In Functional Interface of java.util.function package of Java 8. The consumer interface consumes the object and doesn’t return any object. it has only one abstract method called accept(). Along with this, it has one more default

Java 8: Supplier – Built-In Functional Interfaces
Supplier Interface is another Built-In Functional Interface of java.util.function package of Java 8. Supplier Interface used for assignment purposes. It has only one abstract method and doesn’t have any default or static method. Below is the get() method signature. It

Java 8: Predicate – Built-In Functional Interfaces
Predicate Interface is another Built-In Functional Interface of java.util.function package of Java 8. Predicate Interface can be used to evaluate the expression which returns the boolean result like true or false of the given expression. Example: Predicate logic = X

Java 8: Built-In Functional Interfaces. Supplier, Function, Predicate
Functional Interface was added in Java 8. Functional Interface is like a normal interface with only one abstract method. Remember, a Functional interface can have a default method but should have only one abstract method which is unimplemented. Also, @FunctionalInterface