The next feature to comment on is "anonymous inner class". Instead of declaring an inner class with one Java statement, and then instantiating and using it in another statement, an anonymous class combines the two steps in a single Java expression. An anonymous class is defined by a Java expression, not a Java statement. This means that an anonymous class definition can be included within a larger Java expression such as an assignment or method call. [Flanagan97a, p103, p117]
The ActionListener object is an example. Instead of writing code like:
class ButtonListener implements ActionListener { public void actionPerformed( ... ) { ... } } ActionListener bl = new ButtonListener();Everything is condensed into:
ActionListener bl = new ActionListener() { public void actionPerformed( ... ) { ... } };The WindowAdapter object is even more condensed. Inside the addWindowListener() method invocation, the anonymous inner class expression is embedded. That is why there is an "apparently" extra ");" at the end.
In the first case, we "inline" defined a class and declared an instance of that class. In the second case, we "inline" defined a class, declared an instance of that class, and, passed the instance as an argument to a method invocation.