Re: Smuggling information to enums
Roedy Green wrote:
On Tue, 24 Mar 2009 08:13:51 -0700 (PDT), Jason Cavett
<jason.cavett@gmail.com> wrote, quoted or indirectly quoted someone
who said :
Enums can have constructors, though. See the following example (this
enum is inside the class ActionManager):
The terminology gets confusing. The enum constants have constructors,
but they not mechanisms whereby you can get information from outside
the enum into it so that its methods for example can have some tuning
constants for a particular incarnation of the enum associated with
some class.
The design seems suspect. If the internals of Foo.Enum
are influenced by whether class Bar or class Baz is the first
to run code that causes Foo.Enum to load, what happens when
both Bar and Baz are used in the same program? At least one
of them will be disappointed (barring multiple ClassLoaders,
in which case neither will necessarily be disappointed but
both are likely to be confused).
Another way of putting it is there is no constructor for the enum as a
whole, just a template for the individual enum constant constructors.
What *class* is created by a constructor? Classes get
created by an inscrutable presence hidden behind curtains deep
inside the Emerald Ci-- er, inside the JVM. Why should the
*class* Foo.Enum be different from all others?
There's something I'm still not seeing about your problem ...
--
Eric.Sosman@sun.com