It is not a code block. It is an object.
When you say,
new Runnable()
you are creating an object that implements the Runnable interface, specifically the run()
method.
As the method name suggests, invokeLater()
will invoke the run()
method of your runnable interface implementation object (or Runnable object) at some later point in time.
As another poster mentioned, this is an example of Anonymous Classes. It is really a convenience mechanism to quickly write code in a more concise fashion. If you don't like this, you can do it this way -
Create a new class that implements Runnable -
public class RunnableImplementation implements Runnable
{
public void run()
{
Example ex = new Example();
ex.setVisible(true);
}
}
Then, the code in your example becomes -
SwingUtilities.invokeLater(new RunnableImplementation());