Good day.

There is a main () method, within which the run () method is called:

public static void main(String args[]) { EventQueue.invokeLater(new Runnable() { @Override public void run() { new WorkTable().setVisible(true); } }); } 

NetBeans suggested replacing an anonymous class with a lambda expression:

 public static void main(String args[]) { EventQueue.invokeLater(() -> { new WorkTable().setVisible(true); }); } 

Since the run () method is the only one in the Runnable interface, we are talking about its implementation. But how, in this case, use a lambda expression if the interface has several methods (for example, List)?

Thank you.

  • 2
    No, this is not a Functional Interface by definition - etki
  • I agree that everything that does not apply to functional interfaces does not fall under this kind of simplification. - Dmitry08 4:04 pm
  • @Etki, why does my code from my answer work then? .. - Yuriy SPb
  • Probably, the fact is that the signature in my case is different for all methods - YuriiSPb

1 answer 1

No The documentation clearly states that lambda expressions can only be used for interfaces that have a single method. In fact, lambda expressions are simply syntactic sugars (a more readable and convenient syntax) for anonymous classes. So, work in the old manner (as in the first piece of code).

  • Fully agree, thank you. - Dmitry08