Sunday, July 19, 2015

Java Lambda - ObjIntConsumer Functional Interface

ObjIntConsumer Functional Interface

ObjIntConsumer represents an operation that accepts an argument of type T or object-valued argument and int 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, int value);

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

objIntConsumer.accept("Number is ", 10);

That’s all on ObjIntConsumer 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