Sunday, July 19, 2015

Java Lambda - ObjLongConsumer Functional Interface

ObjLongConsumer Functional Interface

ObjLongConsumer represents an operation that accepts an argument of type T or object-valued argument and long valued argument and returns no result.

This is the specialization of BiConsumer interface. We have discussed it previously. BiConsumer interface represents two input (object) arguments and returns no result. BiConsumer is two-arity specialization of Consumer interface.

accept() method
void accept(T t, long value);

performs this operation on given arguments.  Let us take simple example to accept String object and long value.
ObjLongConsumer<String> objLongConsumer = (final String t, final long a) -> {
            String result = t.concat(String.valueOf(a));
            System.out.println(result);// Outputs Number is 10
      };
      objLongConsumer.accept("Number is ", 10);

That’s all on ObjLongConsumer Interface.

Read about important java.util.function package’s interface here. Consumer, Function, Supplier, BinaryOperator & Predicate Functional Interfaces. I have also written on High Order functions using Function functional interface.



No comments:

Post a Comment

Ads Inside Post