U
U
UNy2018-11-25 21:17:03
Java
UNy, 2018-11-25 21:17:03

Why are lambas better than anonymous classes?

Lamba expressions require the interface to contain only 1 method, while using an anonymous class it can contain as many methods as desired. What is the point of using lamb expressions then?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2018-11-25
@UNy

Even without going deep into the jungle, it is obvious that the lambda is more compact.
than an anonymous class

someButton.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
      JOptionPane.showMessageDialog(this, "Hello!")
  }
});

I
illuzor, 2018-11-25
@iLLuzor

They are better for brevity.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question