Enum constants: UPPERCASE or CameCase?

Independently of language/runtime support my view of a constant is something that has a value that is defined (conceptually) at source writing / compile time. As such it is something that you use as reference and is mostly the JVM constants, but in various cases an immutable object reference can also be a constant. (This kind of coincides with Java’s static final).

If a value is determined at startup time (or otherwise dynamically determined) it is not a constant even if it is immutable. In many ways the way I look at is goes back to the intent of the author, not the capabilities/limitations of the language used to express that intent.

As to capitalisation, that is a tricky one. Conceptually an enum constant/value is constant (although the enum itself doesn’t have to be immutable). There is however a narrower classification that often fits even better and that is object. For most intents and purposes an enum constant functions like an object. As a result I would come to the following rule:

  • If the enum provides/implements an interface it is an object → capitalise like an object
  • If the enum is merely a list of possible values → capitalise like an int constant.