Re: Basic Enum Scope Syntax Question
Roedy Green wrote:
Somewhere along the line I got the idea that enum classes could have
any scope, private through public, but the enum constants could not
have an explicit scope, but by default they were always public.
IntelliJ Inspector started trying to put "private" on my enum
constants, that were not used outside the class. I assume that was
misguided.
Just what are the scope rules. Please don't tell me to read the JLS.
I can rarely make sense of it. My maternal grandfather was a lawyer,
but I somehow missed all his genes.
Since you won't read the JLS, I will. It's not that bad once one gets
used to reading BNF grammars and studying W3C specs.
Inserting "private" before the enum constants is definitely forbidden.
An enum constant is defined syntactically as a series of annotations
followed by an identifier and then the constant's body (where applicable).
Furthermore:
[F]or each declared enum constant with the name /n/ the enum type has an
implicitly declared public static final field named /n/ of type E.
IntelliJ is wrong.
I would prefer a JLS made up of annotated canonical examples that
cover the points. I think such a document would lead to far fewer
errors in implementation as well.
The JLS does have several examples of some of the gotchas of the code,
but they are not as clearly-understood as those in the tutorials
(generics comes to mind).
Further I think there should be a test suite: a giant set of programs
designed to test that the compiler implemented code correctly. You
really should create this before on in parallel to force you to think
clearly about the precise behaviour you want, rather than defining the
desired behaviour in terms of what your reference implementation
produces.
How would the test set work? Imagining that one was writing a compiler
that compiled to native code; even using the x86 instruction set, there
are several equivalent ways to write "x=0;".
I wish there were such a thing for CSS, which would be more difficult
since you can't very well mechanically test the result.
http://www.w3.org/Style/CSS/Test/
http://www.webstandards.org/action/acid2/
There already exist several tests for CSS (many of the WD's for CSS 3
have associated test suites, and one of the requirements for REC status
is to have a test suite). That said, the CSS standard is sometimes
ambiguous in edge cases, so creating a reliable test case can be near
impossible.
The worse problem is that support for CSS is sometimes hard to come
by... *cough* IE *cough* (I'll be fair. Sometimes FF doesn't have the
required standards either. Sometimes even Opera doesn't have it!)
--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth