All Articles

enums III

Enums have a name() method. And it has a very precise meaning. Now imagine:

public enum Day {
  MONDAY("code1"), TUESDAY("code2");

  private final String code;
  private Day(String code) {
    this.code = name;
  }

  public String getName() {
    return code;
  }
}

Now good luck finding out what is Day.name() and what is Day.getName(). You’d be much better off calling this other method of yours getCode(). If name looks like a good name for your attribute, think long and hard to find an alternative.