Variables' name can be changed and shouldn't affect logic. But name() method in Enum returns a constant name as a value so it can break existing code. Should I avoid using name()?
For example,
public enum Example1 {FOO, BAR}
Refactoring FOO name to FOO2 will brake Example1.FOO.name().equals("FOO").
public enum Example2 {
FOO("FOO"),
BAR("BAR");
String code;
private Example2(final String code) {
this.code = code;
}
public String getCode() {
return code;
}
}
In this case, changing FOO name to FOO2 will not brake Example2.FOO.getCode().equals("FOO").