+ 2
What are lambda expressions in java??
please I need help on what are lambda expressions and how they work.
2 Respuestas
+ 3
lambda expressions are Java's first step into functional programming.it's a function which can be created without belonging to any class. It can be passed around as if it was an object and executed on demand.
Imagine you have a class called House Owner which can register House event listeners
public class HouseOwner {
public void addHouseListener(HouseChangeListener listener) { ... }
}
In Java 7 you could add an event listener using an anonymous interface implementation
HouseOwner houseOwner = new HouseOwner();
houseOwner.addHouseListener(new HouseChangeListener() {
public void onHouseChange(House oldHouse, State newHouse) {
// do something with the old and new House.
}
});
In JV 8,add an event listener using a Java lambda expression;
HouseOwner houseOwner = new HouseOwner();
houseOwner.addHouseListener(
(oldHouse, newHouse) -> System.out.println("House changed")
);
The lambda expressions is this part:
(oldHouse, newHouse) -> System.out.println("House changed")
0
thanks