Java Lambda Expression Question

2    21 Jul 2015 15:59 by u/skaiinyght

Hey all, just a quick question. Are lambda expressions just a replacement for anonymous classes or are they for something more?

I really don't mind doing, for example:

SwingUtilities.invokeLater(new Runnable(){
    public void run(){
        new ClassName();
   }
});

Although It does look a little nicer with the lambdas

SwingUtilities.invokeLater(() ->{
    new ClassName();
});

Is it all about saving a line or two? Is this something I should just start doing instead of anonymous classes or does it even matter?

1 comment

1

While the syntax is similar lambda expression are not just syntactic sugar for anonymous inner classes. I recommend you watch this talk from Brian Goetz the architect of Java. I linked to the relevant time stamp where he addresses your question.