I was doing some Minecraft plugin programming and accidentally referenced something initialized at server start (a config file reader) in an enum constructor. To my surprise, it worked! I was under the impression that enums initialized right after static fields. I did some investigating, and the enum constants weren't initialized until after the enable method was already run. This has me wondering: when are enum constants actually initialized?
Asked
Active
Viewed 33 times
1
-
1The key to understanding the duplicate is that `enum` types are specialized class types and enum constants are just `static final` fields of the `enum` class. – Sotirios Delimanolis May 21 '15 at 02:56
-
@markspace Enum constants must be the first thing defined in an `enum` body, if that's what you mean. – Sotirios Delimanolis May 21 '15 at 03:06