Chris Uppal wrote:
> maxw_cc wrote:
>
>
>>Can somebody please tell me a practical reason why you couldn't have
>>static members (not constants) within an inner class? I know that this
>>is forbidden, but I haven't found a practical, concrete reason for
>>this... I was wondering if this was just a whimsical decision from the
>>designers of the language.
>
>
> Put it down to whimsy.
>
> I think there was some feeling that it couldn't be needed, and that forbidding
> static members made the construct somehow "cleaner" (which is laughable).
I think the prohibition protects novice and journeyman programmers who
might be inclined to assume that inner classes' static members (if they
could have any) were scoped to a particular enclosing class instance.
The inner class itself is not static after all. (Weak, I know.)
Certainly it is the case that since all inner classes must have a static
or top-level containing instance, the inner class' static data can be
assigned to the class of that containing instance.
> There is no *technical* reason for it in the sense that the current
> implementation would work just as well if static members were allowed.
Yes, that's absolutely true. I do wonder whether the designers at the
time were also trying to hedge against a future implementation where the
difference might matter, however.
John Bollinger