Re: Is there a limit to the number of "things" in an enum
printdude1968@gmail.com wrote:
Furthermore, I like the book very much. I just found it odd that a
question I had posted earlier about enums was being addressed in the
book and I was looking for a bit of clarification...apparently I was
wrong...again
I don't think you can blame yourself for this one. There is a ton of
literature out there describing a moving target, and people were calling
"type-safe enums" with the e-word before Sun adopted it as a keyword. As good
a book as /Effective Java/ is, this is an area where it's the victim of the
march of time.
There is a learning technique called "straw man". You present an idea, such as
"prefer classes over enums because Josh Bloch said so". Then you present it
and people respond with new information that confirms or denies the truth of
the hypothesis. In science there is no failure outcome to an experiment.
In this case you are the victim. I hoped only to clarify the confusion caused
by that chapter.
Look at the issue this way: Joah Bloch's chapter on type-safe enums was one of
the motivations for the current Java syntax. Everything he said about the
benefits of doing it by hand, very handy if you have to work on old Java
versions for customers as I do, applies to the new 'enum' construct, not
coincidentally. Java enums really are classes, so it's no surprise.
This language in the JLS supports the notion of an enum as a special kind of
class:
<http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.9>
The optional class body of an enum constant implicitly defines an anonymous class declaration (??15.9.5) that extends the immediately enclosing enum type. The class body is governed by the usual rules of anonymous classes; in particular it cannot contain any constructors.
-- Lew