Java syntax allows you to create instances of anonymous types without much boilerplate. This approach is commonly use to implement single-use instance of Single Abstract Method-style interfaces such as Comparable
and Runnable
:
new Thread(new Runnable() {
@Override
public void run() {
System.out.println("Hello, world!");
}
}).start();