JavaIntermediate#inner-classes

What are anonymous inner classes used for?

They let you instantiate a class or implement an interface with a one-off implementation inline, without a separate named class file, commonly used before lambdas for event handlers or Runnables.

Example
Runnable r = new Runnable() {
  @Override public void run() { System.out.println("running anonymously"); }
};
r.run();

Related Questions

1
JavaIntermediate#inner-classes

What is a local class in Java?

Open
2
JavaBeginner#fundamentals

What is the difference between an enum and a class with constants?

Open
3
JavaIntermediate#fundamentals#java14

What are records in Java (Java 14+)?

Open