This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inner Classes

 
Vineela Devi
Ranch Hand
Posts: 191
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can anyone tell what is the use /advantages of having Inner classes.Tell me a real world scenraio when we may need them.

Regards,
Vineela
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Common use: as event listener classes in Swing GUIs.

Advantage: listeners are often small classes that know implementation details of their enclosing classes. This is a good match for nested classes.

Disadvantage: code reuse. But when you realize a listener can be turned into a useful top-level class (for example the Action behind the exit menu item), you refactor. Most of the time event listeners are too specific for you to consider reuse.
 
Jan Groth
Ranch Hand
Posts: 456
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
creating a class that implements the Comperator interface can be done on the fly as a anonymous inner class. that can be by far the easiest solution if you need to pass a Comperator into a method call, even though i go with poster #1 - the code is not so reusable...

jan
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic