aspose file tools*
The moose likes Beginning Java and the fly likes Anonymous versus Declared inner classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Anonymous versus Declared inner classes" Watch "Anonymous versus Declared inner classes" New topic
Author

Anonymous versus Declared inner classes

Dan Grindstaff
Ranch Hand

Joined: Sep 24, 2006
Posts: 138
Hello All, What is the advantage of using an anonymous inner class over a declared inner class?
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
I know of no technical advantages of one over the other as far as speed, resources used, etc, but for very small classes that are not reused, anonymous inner classes may make the code simpler and easier to read (for some) since the functionality of the class is held right where you're wanting to use it. Overuse and inappropriate use will have the opposite effect.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
It is quicker to write. If you are going to use objects of that class in several places, however, or similar objects, you are probably better of with a declared and named class (inner or top-level).
Dan Grindstaff
Ranch Hand

Joined: Sep 24, 2006
Posts: 138
Thank you!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Anonymous versus Declared inner classes