Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

nested vs. inner

 
Stephen Suen
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
I'm wondering how I can make a choice between nested classes and inner classes, particularly when both implementation are really applicable.
Considering for the hiding, efficiency and other factors, is there any
difference between two implmentations?
Thanks for any advise
Stephen Suen
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All inner classes are also considered nested. I'm guessing you're asking if it's better to use inner classes or static nested classes. I'd say that if you don't need to access an outer "this" reference then static nested is simpler, and easier for others (especially beginners) to understand. But if you have a legitimate use for an outer this reference, go ahead and use an inner class instead. In other words, use "static" in the class declaration unless and until your compiler complains, then change it if necessary.
Alternately if your (inner/nested) class is really short and simple, you might just want to declare it as an anonymous class instead - which is a kind of inner class, not static. Anonymous classes can be relatively compact, which is nice if the class is really simple.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic