> But that just invites the next question: /why/ can we not define static local
> classes ?
For exactly the same reason you cannot define static local variables,
I guess...
Chris Uppal - 05 Oct 2006 12:57 GMT
[me:]
> > But that just invites the next question: /why/ can we not define static
> > local classes ?
>
> For exactly the same reason you cannot define static local variables,
> I guess...
But that just invites the /next/ question -- why can we not define static
fields with scope limited to one method (or a smaller block) ?
Up until a few years ago, I would have though that it was because that feature
(although trivially simple to implement) was contrary to the themes of
simplicity and "no gross hacks" which are two legs of the Sprit of Java.
Unfortunately, the spirit of Java has been so thoroughly defiled by the last
several generations hacks forced into the language, that adding static
variables would seem almost benign by comparison. Indeed there seems to be
little left at all of the Spirit of Java :-(
So I think the question stands unanswered.
-- chris
Hendrik Maryns - 05 Oct 2006 16:10 GMT
Chris Uppal schreef:
> So I think the question stands unanswered.
Which made me create an RFE, numbered 809880, which apparently has to be
evaluated internally at Sun’s first. I’ll report on it.
H.
- --
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
Chris Uppal - 06 Oct 2006 11:51 GMT
[me:]
> > So I think the question stands unanswered.
>
> Which made me create an RFE, numbered 809880, which apparently has to be
> evaluated internally at Sun's first. I'll report on it.
<melodramatic howl>
Oh my God ! What have I done ?!
</melodramatic howl>
;-)
-- chris
>> but I can't seem to find a way to define an enum inside a block of java
>> code. What's the syntax for doing this, or is it impossible? And if it's
>> impossible, can anyone think of a good reason why it's impossible?
>
> Probably because you can't have static local classes, and enums are always
> static.
Of course you can have static local classes.
class HasLocalStatic
{
static void method()
{
class LocalStatic
{
void doit()
{
}
}
LocalStatic ls = new LocalStatic();
ls.doit();
}
}
(You didn't want one inside an instance method, did you? Admittedly, it's
illegal to specifically mark LocalStatic as a static class, even though it
clearly is one. A further admission is that reflection doesn't consider
LocalStatic to be static. Still, having no enclosing member, it's clearly a
static class.)
But even inside a static method, enum declarations are forbidden.
Chris Uppal - 05 Oct 2006 11:53 GMT
Mike Schilling wrote:
> Of course you can have static local classes.
[...]
I hadn't considered that case. Thanks for pointing it out.
> Admittedly, it's
> illegal to specifically mark LocalStatic as a static class, even though it
> clearly is one.
They probably thought that would be too confusing ;-)
> A further admission is that reflection doesn't consider
> LocalStatic to be static.
And another little cockup ;-)
> But even inside a static method, enum declarations are forbidden.
Yes, that makes /lots/ of sense...
-- chris