The Inner that is named is not the true Inner.
Actually, he only made a convincing argument for the case of local classes. He was not convincing at all about non-static member classes, which is the question opening this thread. He said:Jim Yingst has proposed a very convincing explanation. June 29, 2003 03:08 PM
[MM]: Perhaps inner member classes could have static fields?
Perhaps, but I think these would be subject to similar problems and confusions. Consider two InnerMember instances which were associated with two different instances of an Outer class. If Inner had a static field, should it have just one value for all Inner instances, or just for Inner instances associated with the same Outer instance? I would favor the latter, but again it would not be obvious, and again that static field of Inner could just be made a static or nonstatic field of Outer instead.
The Inner that is named is not the true Inner.
I disagree. If non-static member classes (referred to as "inner member" in the above - more on that below) could have static members, they should definitely have one set of static data, just like their static brethren. How then could they be any more confusing than static member classes? The only distinction between the two would be that non-static member classes require an enclosing instance of their enclosing class for instantiation.
The Inner that is named is not the true Inner.
I believe you're pointing out that since static vars of the outer class are visible to the inner class, allowing their declaration in the inner class could be looked at as redundant. Of course, I could argue by extension that the instance vars of Outer are also visible to Inner, so their declaration in Inner is also redundant. So by extension there is no point in allowing any member vars in Inner - we can just declare them all in Outer. I'm following out this reasoning to point up a very good reason for allowing member classes to declare member variables, static and instance: scoping. Declaring variables to have scope larger than the context in which they are actually used is a source of bugs.
But my point isn't really about that. It's about the way we think and talk about nested classes, the fact that it is conflicted, and that a small tweak in the rules about member classes would undo much of the knottiness.
[ September 17, 2003: Message edited by: Steve Lovelace ]
SCJP, Pre-SCJD (URLyBird 1.3.1), Teradata Cert'd Prof
oc.InnerClass ic[] = new oc.InnerClass [3];
The Inner that is named is not the true Inner.
The Inner that is named is not the true Inner.
Originally posted by Steve Lovelace:
I want this to be true, but it isn't. I want this to be the definition of inner. This is a large part of why I'm writing these frightful essays.
Originally posted by Steve Lovelace:
There is no reason why static members would be bound to an instance. The inner class has its Class object and the static members can be bound to that. This may already be happening. As Marlene pointed out recently, the assert mechanism is sneaking unseen static members into inner classes. I'd love to know the details.
Originally posted by Steve Lovelace:
To what instance is it bound? There simply is no enclosing instance. This is a little off topic anyway since we are talking about member classes, which do not evaporate from the stack.
The Inner that is named is not the true Inner.
Originally posted by Steve Lovelace:
This conversation is like every other nested class conversation. You say "inner", and then a couple of paragraphs later, or a response later, are obliged to state what you really meant by "inner".
Originally posted by Steve Lovelace:
It's always like that, and that is what my rant is about.
Originally posted by Steve Lovelace:
You are very ably pointing out practical considerations which allow you to say, on good grounds, what's the point of static members in non-static member classes? (Though apparently Sun has found a point.)
The Inner that is named is not the true Inner.
Tick check! Okay, I guess that was just an itch. Oh wait! Just a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|