"Enums are bad news," Diego's boss would often say, "they don't add any real value to the code, and they're that much more 'bloat' from Java. I've been coding in C for 20 years, and did just fine without them."
Despite being the senior Java architect, Diego's boss had deep-rooted distaste for Java. Diego didn't really understand why there was such a hatred against Enums specifically, until he stumbled across some of the architect's code.
public enum Status {
CREATED,
OPEN,
CLOSE,
TERMINATED;
}
... snip to actual usage of the enum ...
public Integer checkStatus(Status status){
String statusStr=status.name();
Integer checkedStatus=null;
if (statusStr==Status.CREATED.name()||statusStr.equals(Status.CREATED.name())){
checkedStatus=Status.CREATED.ordinal();
}else if (statusStr==Status.OPEN.name()||statusStr.equals(Status.OPEN.name())){
checkedStatus=Status.OPEN.ordinal();
}else if (statusStr==Status.CLOSE.name()||statusStr.equals(Status.CLOSE.name())){
checkedStatus=Status.CLOSE.ordinal();
}else if (statusStr==Status.TERMINATED.name()||statusStr.equals(Status.TERMINATED.name())){
checkedStatus=Status.TERMINATED.ordinal();
}
if(checkedStatus==null){
return null; //Shouldn't never happen
}else{
return checkedStatus;
}
}
Just for reference, how could be rewritten it in a single line:
public Integer checkStatus(Status status){
return status.ordinal();
}