How do I create a constructor for an anonymous class?

John Zukowski

Since anonymous classes don't have names, you cannot create a constructor by just using the name of the class. What you can do instead is to use an "instance initializer". Instance initializers basically look like methods with no names or return values:

ActionListener listener = new ActionListener {
    System.out.println("Instance Initializer");
  public void actionPerformed(ActionEvent event) {