This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
There are examples of anonymous classes here, and in the older links mentioned.
A local class would look something like thisI'll let you work out how many bits of bad design there are in that code
Remove one erroneous } and new line from code
In sticking with Campbell's example, an anonymous class would look like this:
Difference here is you create an actual concrete implementation of the Comparator interface "on the fly" and give it no name/reference assignment. You can't refer back to it later or anything.
This can be useful if/when you have no other use for the Comparator outside the scope where it is used for example. It looks wierd at first to those who are not used to it because you are using the 'new' keyword to instantiate an Interface which you normally can't do except when you are making an implementation of it at the same time like this.