Wednesday, July 22, 2015

Java Lambda - ToLongBiFunction Functional Interface

ToLongBiFunction Functional Interface

Before we begin to discuss about ToLongBiFunction interface we need to know about BiFunction interface. BiFunction interface represents a function that accepts two arguments T and U and returns result of type R. Input and result are of type Object. Previously we have discussed about BiFunction interface and Function interface. I would highly recommend you to read it. I also have written on higher order functions.

ToLongBiFunction interface represents a function that accepts two argument of type T and U and returns long-valued result.

ToLongBiFunction Interface Declaration

public interface ToLongBiFunction<T, U>
T and U are the input types.



applyAsLong() method

long applyAsLong(T t, U u);
T and U are input for the method applyAsLong(). This function applies the given arguments and returns long result. Let us take simple example of accepting two strings and returning their length.

ToLongBiFunction<String, String> longBiFunc
                                      (str1, str2)->str1.length()+str2.length();
long result = longBiFunc.applyAsLong("Dell", "Microsoft");
System.out.println(result); //Outputs 13



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