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 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<Double> pi = () -> (22.0/7);




In this article, we have seen about supplier interfaces and other primitive specialized interfaces.

Java 8 Stream APIs

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

Read More »