+ 2

What are lambda expressions in java??

please I need help on what are lambda expressions and how they work.

28th Jun 2017, 10:46 PM
Christopher Vegerano
Christopher Vegerano - avatar
2 odpowiedzi
+ 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")
28th Jun 2017, 11:32 PM
Amil Jayasinghe
Amil Jayasinghe - avatar
0
thanks
29th Jun 2017, 1:11 AM
Christopher Vegerano
Christopher Vegerano - avatar