In this recipe, you will learn how to use lambda expressions in practice.
Using lambda expressions
Getting ready
Creating and using lambda expressions is actually much simpler than writing a method. One just needs to list the input parameters, if any, and the code that does what has to be done.
Let's revisit our implementation of standard functional interfaces from the first recipe of this chapter and rewrite them using lambda expressions. Here's how we have implemented the four main functional interfaces using anonymous classes:
Function<Integer, Double> ourFunc = new Function<Integer, Double>(){
public Double apply(Integer i){
return i * 10.0;
}
};
System.out.println(ourFunc.apply(1)); ...