What is ObjLongConsumer functional interface in Java?

ObjLongConsumer is a functional interface that accepts an object-valued and a long-valued argument as inputs and produces no output. The interface contains one method i.e., accept.

The ObjLongConsumer interface is defined in the java.util.function package. To import the ObjLongConsumer interface, check the following import statement.

import java.util.function.ObjLongConsumer;

The accept() function

The accept() function is the functional method of the interface that accepts an object and a long input and performs the given operation on the inputs without returning any result.

Syntax

void accept(T t, long value)

Parameters

  • T t - The first object argument.
  • long value - The long input argument.

Return value

The method doesn’t return any results.

Code

import java.util.function.ObjLongConsumer;
public class Main{
public static void main(String[] args) {
// Implementation of ObjLongConsumer
ObjLongConsumer<Integer> objLongConsumer = (i1, l1) -> System.out.println(i1 + " + " + l1 + " = " + (i1 + l1));
Integer i1 = 100;
long l1 = 1223432;
// calling the accept method
objLongConsumer.accept(i1, l1);
}
}

In the code above, we create an implementation of the ObjLongConsumer interface that accepts an integer as the object argument and a long argument. It prints the sum of the arguments to the console.

Free Resources