Showing posts with label anonymous. Show all posts
Showing posts with label anonymous. Show all posts

Wednesday, May 4, 2016

Anonymous class that “extends” other class or “implements” some interface in Java?

Anonymous classes in Java are defined in this way:

Syntax for implementing some interface:
Runnable r = new Runnable() {
   public void run() { ... }
};

Syntax for extending other class (is the same):
SomeClass x = new SomeClass() {
   ...
};