R
Roedy Green
Perhaps I'm missing something, but this seems simple: To
initialize the static field, you need to construct an enum
instance for it to refer to. How can the constructor get the
value of a reference to an instance that has not yet finished
being constructed?
In a regular class, statics are initialised before any instance
variables. The enum constants are a sort of implied static
initialisation.
What if the language had been defined so the enum constants were
created (i.e. their constructors run) after the other static
initialisation?
The disadvantage is statics could not refer to enum constants.
So what if you had allowed two sets of static inits, one before the
enum definitions, and one after. In other words, allow the programmer
to determine the order of initialisation. Let him figure out how best
to avoid forward references.
--
Roedy Green Canadian Mind Products
http://mindprod.com
"Patriotism is fierce as a fever, pitiless as the grave, blind as a stone, and as irrational as a headless hen."
~ Ambrose Bierce (born: 1842-06-24 died: 1914 at age: 71)