ObjLongConsumer Interface is a part of the java.util.function package which is introduced in Java 8. It is an in-built Functional Interface. This function expects an object-valued and a long-valued argument as input but produces no output. In this post, we are going to see several implementations of ObjLongConsumer Interface by using different examples.

ObjLongConsumer_Interface_Java8_Techndeck

ObjLongConsumer Interface in Java 8 with Examples...!!! Share on X

Look at ObjLongConsumer Javadoc description below:

LongConsumerInterface_Signature_Java8_Techndeck

ObjLongConsumer Interface contains following method:

accept

Let’s discuss this method:

accept 

This method performs operation on the given argument and return no result.

void accept(T t, long value);

Below is an example to demonstrate accept() method:

Example 1. with Integer

import java.util.function.ObjLongConsumer;

public class ObjLongConsumerInterfaceJava8Example1 {

    public static void main(String args[]) {

        System.out.println("Ex. 1 - ObjLongConsumer - Integer example \n");

        ObjLongConsumer <Integer> objLongConsumberObj = (t, value) -> System.out.println(t * value);

        objLongConsumberObj.accept(5, 10 L);

    }
}

Example 2. with String

import java.util.function.ObjLongConsumer;

public class ObjLongConsumerInterfaceJava8Example2 {

    public static void main(String args[]) {

        System.out.println("Ex. 2 - ObjLongConsumer - String example \n");

        ObjLongConsumer <String> ObjLongConsumberObj = (t, value) -> {
            if (t.length() > value) {
                System.out.println("String is bigger than the expected value.");
            } else if (t.length() == value) {
                System.out.println("String lenght is equal to expected value.");
            } else {
                System.out.println("String is shorter than the expected value.");
            }
        };

        ObjLongConsumberObj.accept("justanordinarywriter.com", 15 L);

        ObjLongConsumberObj.accept("techndeck.com", (long) 15);
    }
}

Java 8 ObjLongConsumer Interface is an absolute useful addition as part of ‘Functional Interfaces’ and can serve variety of purposes. It is quite powerful as it can be used as a higher order functions through lambda functions and above examples could help you to get better idea on how to implement it.

ObjLongConsumer Interface in Java 8 with Examples...!!! Share on X

Do you like this Post? – then check my other helpful posts:

Other Useful References:

Author

  • Deepak Verma

    Deepak Verma is a Test Automation Consultant and Software development Engineer for more than 10 years. His mission is to help you become an In-demand full stack automation tester.

    He is also the founder of Techndeck, a blog and online coaching platform dedicated to helping you succeed with all the automation basics to advanced testing automation tricks.

    View all posts