Pat Farrell wrote:You can fix it by reordering your code.
Except with enums, because the enum constants need to be the first thing in the code.
A workaround is usually to use a helper class:
The reason it didn't work before is the way enums are handled when the class is loaded: first the enum constants are created, and any static fields are only instantiated after that. The enum constants cannot access anything that has not been initialized yet.
With this workaround, the enum constants ask for the Orientation fields. This causes the Orientation class to be loaded. This class is independent of the enum class, so its static fields are initialized without a problem. These can then be used in the enum constants.