posted 15 years ago
If you really, really want to, and you really, really shouldn't, you could declare an inner class inside the enum. The inner class can declare and initialize static fields before the enum constructor runs, and make them accessible to the constructor.
This modified version of your code sample will actually initialize the member value of Enum.A to char value 'a', Enum.B to char value 'b' and Enum.C to char value 'c', as soon as the Enum is used. The initial Enum.next() call will therefore yield char value 'd' and subsequent calls will continue to increment the value of the static field. So the output should read:
d
a
b
c
e
[ August 15, 2008: Message edited by: Jelle Klap ]
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.