Hello all, In this post we are going to talk about functions as first class citizens and it's usages.
The easiest way to understand is to analyze a demonstration. Package
java.util.function in java 8 contains all kinds of single method interfaces. In this samples we are going to use the java.util.function.Function and java.util.function.BiFunction interfaces.
|taken from - https://www.linkedin.com/topic/functional-programming|
1. Create an inline lambda expression and store in a variable.
to call the above method we can do as follows.
2. Create a static method that fits into the signature of the BiFunction interface, then assign it to the variable and invoke.
3. Create a instance method that fits to the signature of the BiFunction interface. In this approach, first we have to create the instance to acquire the function variable.
Now take an example, how to pass functions as variables and do some stuff.