File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Anonymous versus Declared inner classes

 
Dan Grindstaff
Ranch Hand
Posts: 138
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All, What is the advantage of using an anonymous inner class over a declared inner class?
 
pete stein
Bartender
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 138
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you!
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic