Skip to main content

How to tell Java to apply a lambda expressions for a custom functional interface instead for the one from the method's contract?

Posted by kocko on June 19, 2014 at 10:11 PM PDT

The lambdas are without any doubt one of the most intriguing and attractive features in Java8, but sometimes instead of helping us writting a better and boilerplateless code, they can get us into trouble. And still, they are the better alternative to the anonymous classes for lots of reasons.

The anonymous classes were a nice way to achieve clojures in Java, but it was something natural to write a lot of boilerplate code to achive something atomic. Let take a look on the following code snippet:

myButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {

Related Topics >>