From: markspace on
Arne Vajh�j wrote:

> On 12-12-2009 17:15, Rit wrote:
>> By local classes I mean classes declared in local blocks.

> I think they are mostly a certification thingy. I don't think I
> have ever seen real world code using it.


Except of course for anonymous local classes, which I'm sure you've seen
quite a few of. ;)
From: markspace on
Rit wrote:

>
> Thanks for your response. Local classes in static context do no have
> an enclosing object. What could happen if nsmc, local classes or
> anonymous classes had static members. Why can't Local classes in
> static context have static members at least ?


I didn't look this up but: I'm pretty sure that while you are correct
that local classes in a static context have no enclosing *object* they
do have an enclosing *class*. That's what I'm referring to, the class
object itself. Not an instantiation of said class object.

Even local classes in a static context have an outer, enclosing class
which can be used for any needed static members, like constants or methods.
From: Lew on
Arne Vajhøj wrote, quoted or indirectly quoted someone who said :
>> I guess you could do that.
>
>> But then what benefits would that static method provide
>> that a similar non-static method would not provide?
>

Roedy Green wrote:
> same thing a normal static method does:  single copy of variable
> common to all instances, persistence, ability to count instances.
>

Let's see. If it's a local class without an enclosing instance (e.g.,
in a static context), there will not be more instances than are
declared in that invocation of the context. A variable can be shared
by making it a final variable in the context outside the local class.
Counting the instances will be useless.

If it's an inner class with an enclosing instance, do you want the
static member shared across all enclosing instances or only among
invocations within the same enclosing instance? How "static" should
'static' be?

It just doesn't make sense to have static members in inner classes.

--
Lew

From: Arne Vajhøj on
On 16-12-2009 20:26, Mike Schilling wrote:
> Arne Vajh�j wrote:
>>> By nsmc I mean non static member classes.
>>
>> Ah.
>>
>> Somebody made a decision.
>>
>> Given that such classes are tied to something non-static (the
>> instance of the surrounding class), then the use of static would
>> be bit fuzzy in semantics.
>
> No, it wouldn't. You can dicuss it all you like, but it's quite clear that
> the only sensible decision is one copy of each static per Class instance.
> (It might be fuzzy if the msmc and its parent class could be loaded by
> different classloaders, but that's not possible.)

I am not sure that I would call that sensible.

It is not exactly "classic static behavior".

Arne