June 2004
Intermediate to advanced
848 pages
21h 28m
English
It's possible to go one step further from a local inner class to something called an anonymous class. An anonymous class is a refinement of inner classes, allowing you to write the definition of the class, followed by the instance allocation.
The anonymous class is explained in Table 12-4.
Table 12-4. Anonymous class
|
Java term |
Description |
Example code |
|---|---|---|
|
Anonymous class |
This is an inner class. It is a variation on a local class. |
void foo () { JFrame jf = new JFrame(); jf.addEventHandler( new EventAdapter() { myOverridingMethod(){ /* some code */ } // end method } // end anon class );} |
|
The class is declared and instantiated within a single expression. |
Read now
Unlock full access