Re: non-static method gotcha
- From: Lew <lew@xxxxxxxxxxxxx>
- Date: Mon, 16 Mar 2009 14:32:24 -0700 (PDT)
Lew wrote, quoted or indirectly quoted someone who said :
The reason is that enums with bodies are implemented as nested subclasses of
the declared enum, 'SubmissionSite' in your example.
Roedy Green wrote:
To be precise, they are implemented as anonymous inner classes definedEven more gory details:
in a static init block. Seehttp://mindprod.com/jgloss/enum.html#HOOD3
<http://java.sun.com/docs/books/jls/third_edition/html/
classes.html#8.9>
There's a bit of a nomenclature question that the mindprod example
raises in its 'Breed' example. The decompiled enum's nested class is
as follows (from Roedy's link upthread):
static final class BreedI$1 extends BreedI
{ ... }
Note the keyword 'static'. According to the JLS (§ 8.5.2):
The static keyword may modify the declaration of a
member type C within the body of a non-inner class T.
Its effect is to declare that C is not an inner class.
Yet the JLS (§ 15.9.5) also says:
An anonymous class is always an inner class (§8.1.3);
it is never static (§8.1.1, §8.5.2).
The enum section (§ 8.9) says:
The optional class body of an enum constant implicitly
defines an anonymous class declaration (§15.9.5) that
extends the immediately enclosing enum type.
So I am nonplused by the presence of the 'static' keyword in the
decompiled anonymous class. My guess is that this is the workaround
for anonymous classes in a static context - they are effectively
static even if not formally so.
--
Lew
.
- Follow-Ups:
- Re: non-static method gotcha
- From: Roedy Green
- Re: non-static method gotcha
- References:
- non-static method gotcha
- From: Roedy Green
- Re: non-static method gotcha
- From: Lew
- Re: non-static method gotcha
- From: Roedy Green
- non-static method gotcha
- Prev by Date: Re: throwing away output
- Next by Date: Re: non-static method gotcha
- Previous by thread: Re: non-static method gotcha
- Next by thread: Re: non-static method gotcha
- Index(es):
Relevant Pages
|