I’m new to Java. I tried to look up on this grammar but could not find it. Could you please point out what this 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 with type ActionListener? And the stuff {..} after new a junk of code for the object? I am confused. Normally I see something like:
[MODIFIER] [TYPE] obj = new [TYPE]();
But in the case above, it is:
[MODIFIER] [TYPE] obj = new [TYPE](){...};
This type of class is called anonymous class.
It declares and instantiates a class that implements
ActionListener.