Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java
communitycreator

What is the ObjDoubleConsumer functional interface in Java?

abhilash

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

ObjDoubleConsumer is a functional interface that expects an object-valued and a double-valued argument as input and produces no output. The interface contains one method, accept.

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

import java.util.function.ObjDoubleConsumer;

The accept method

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

Syntax

void accept(T t, double value)

Parameters

  • T t: The first object argument.
  • double value: The double input argument.

Return value

The accept method doesn’t return a result.

Code

import java.util.function.ObjDoubleConsumer;
public class Main{
public static void main(String[] args) {
// Implementation of ObjDoubleConsumer
ObjDoubleConsumer<Integer> objDoubleConsumer = (i1, d1) -> System.out.println(i1 + " + " + d1 + " = " + (i1 + d1));
Integer i1 = 100;
double d1 = 12.32;
// calling the accept method
objDoubleConsumer.accept(i1, d1);
}
}
Code demonstration of functional method accept

Explanation

In the code above, we create an implementation of the ObjDoubleConsumer interface that accepts an integer i1 as the object argument and double d1 as a double value argument. Our code prints the sum of the arguments to the console.

RELATED TAGS

java
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring