Lambda expressions add a new ability to the Java language: to pass a function as an argument to another method. Before lambda expressions you could do something similar using anonymous inner classes and functional interfaces, but the result code became less legible and clear:
1 2 3 4 5 6 7 8 9 10 11 12 |
// Anonymous inner class (h) and functional interface (Handler) Handler h = new Handler<Event>() { @Override public void handle(Event e) { print(e); } }); // Equivalent Lambda Expression. Simpler, isn’t it? Handler h = (Event e) -> print(e); |
Lambda expressions let you create ..Continue Reading