About this question
Several times I've seen people use title-case or even all lower-case naming for enum constants, for example:
enum Colour {
red,
yellow,
green;
}
This makes working with their string form simple and easy, if you want to throw a new IllegalStateException("Light should not be " + colour + "."), for example.
This seems more acceptable if the enum is private, but I still don't like it. I know I can make an enum constructor with a String field, and then override toString to return that name, like this:
enum Colour {
RED("red"),
YELLOW("yellow"),
GREEN("green");
private final String name;
private Colour(String name) {
this.name = name
}
@Override public String toString() {
return name;
}
}
But look how much longer that is. It's annoying to keep doing if you have a bunch of small enums you want to keep simple. Is it okay to just use unconventional case formats here?