Java 8 LongSupplier Interface

7 months ago codedestine 0

In this tutorial, we will learn about Java 8 LongSupplier interface.

Java 8 LongSupplier Interface

LongSupplier Interface :-

LongSupplier ( java.util.function.LongSupplier ) is a functional interface that has one abstract method declared in it. This interface is long producing primitive specialised form of Supplier interface. 

Abstract method :- 

long  getAsLong (  ) :- The abstract method getAsLong (  ) is a functional method. It does not accept any argument but return newly generated long values in the stream. It represents an operation by which you can generate new long values in the stream.

Reference :-  LongSupplier Interface JavaDocs 

Example :- 

This example will show you, how to create and call different methods of a LongSupplier interface.

  public static void main(String[] args){
 
    LongSupplier longSupplier = ( ) -> { return 500000; };
    System.out.println(longSupplier.getAsLong());
 
 }  

Result :- 

500000 

That’s all for Java 8 LongSupplier Interface. If you liked it, please share your thoughts in comments section and share it with others too.