• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

why not static members in inner classes?

 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Cowgirl and Author
Posts: 1589
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't you like Kathy's one?
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic