Java grammar on weird ActionListener

I am new to Java. I tried to find this grammar, but could not find it. Could you please indicate what it is?

class actions{ ... public ActionListener WHATISTHIS = new ActionListener () { public void actionPerformed (ActionEvent event) { String action = event.getActionCommand (); show_error ("Key unimplemented: " + action + ": " + keys.valueOf (action).get_html ()); refresh (action); } }; ... 

Is WHATISTHIS an object of type ActionListener? And the stuff {..} after the new garbage code for the object? I'm confused. Usually I see something like:

 [MODIFIER] [TYPE] obj = new [TYPE](); 

But in the case above, this is:

 [MODIFIER] [TYPE] obj = new [TYPE](){...}; 
+4
source share
2 answers

This type of class is called an anonymous class .

It declares and instantiates a class that implements ActionListener .

+4
source
 public ActionListener WHATISTHIS = new ActionListener () 

Anonymous inner class in java. It creates an instance of a class that implements ActionListener . Anonymous inner classes have no name. please look here

+2
source

Source: https://habr.com/ru/post/1443920/


All Articles