I'm following this Swing tutorial and I ran across this snippet of code:
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
SimpleExample ex = new SimpleExample();
ex.setVisible(true);
}
});
What's happening inside the EventQueue.invokeLater params?
invokeLaterexpects an argument of typeRunnable, i.e. an instance of a class implementing theRunnableinterface. In this example, this method receives an instance of an anonymous class that implementsRunnable.Runnableonly has a single method -run- so all the anonymous class instance has to implement is thatrunmethod.In Java 8, there's an even shorter syntax, using a lambda expression :