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

why not static members in inner classes?

 
Marlene Miller
Ranch Hand
Posts: 1392
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q1: Why are static members not allowed to be declared in inner classes?
Q2: Why are static members allowed to be inherited by inner classes if they are not allowed to be declared in inner classes?
[ April 25, 2003: Message edited by: Marlene Miller ]
 
Kathy Sierra
Cowgirl and Author
Rancher
Posts: 1589
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy
A static member has to be accessible *without* necessarily having an instance of the class with the static member. But... an inner class (non-static nested class) has no meaning in life until it's instantiated.
But the inner class can *inherit* them, because once the inner class is instantiated, it has access to everything in the enclosing class instance to which the inner class instance is tied. So to be a truly good 'helper' to the enclosing class *instance* (which is the way I think about inner class objects-- as helpers to the outer object), it would need access to everything, statics included. But again, since an inner class has no meaning until its instantiated, there'd be no point in putting statics in it.
Does that make any sense? I've never actually thought about this, although it seems like a pretty significant point!
cheers,
Kathy
 
Jose Botella
Ranch Hand
Posts: 2120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't you like Kathy's one?
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jose Botella:
Don't you like Kathy's one?

Yes, I do like Kathy's post but I started to write it before Kathy posted her's. Then I deleted mine before you posted yours.
I actually started to write an explanation similar to Kathy's but then I backed away from it because I thought that I might be starting a long debate on the design choices for Java.
 
Jose Botella
Ranch Hand
Posts: 2120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It happens to me all the time.
[ April 25, 2003: Message edited by: Jose Botella ]
 
Marlene Miller
Ranch Hand
Posts: 1392
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Kathy. I understand what you mean by a helper object. That makes sense.
Suppose several inner class objects wanted to share some class data, such as an identifier or an ArrayList.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic