Apr 4, 2014

The function interfaces and Lambda expressions are going to make your code concise when coding with Java 8. These are the most awaited features among Java developers. If you understand these 2 examples, you will find the other parts easier to understand.

Q. What is a Lambda expression?A. Lambda expressions are anonymous methods which are intended to replace the bulkiness of anonymous inner classes with a much more compact mechanism. Q. What is a functional interface?A. The annotation @FunctionalInterface is being introduced. This annotation acts similarly to @Override by signaling to the compiler that the interface is intended to be a functional interface. The compiler will then throw an error if the interface has multiple abstract methods.

Step 2: Define the SumTest class and provide the Lambda expression to sum 2 numbers. You can think of it as method implementation of sum(int input1, int input2) defined in the functional interface above.