private String GetFacilityName(String facilityHexID) {
if (facilityHexID.equals(FACILITY_AIRCON_HEX_ID)) {
return FACILITY_AIRCON_NAME;
}
else if (facilityHexID.equals(FACILITY_FAN_HEX_ID)) {
return FACILITY_FAN_NAME;
}
return facilityHexID;
}
Or
private String GetFacilityName(String facilityHexID) {
if (facilityHexID.equals(FACILITY_AIRCON_HEX_ID)) {
return FACILITY_AIRCON_NAME;
}
else if (facilityHexID.equals(FACILITY_FAN_HEX_ID)) {
return FACILITY_FAN_NAME;
}
else {
return facilityHexID;
}
}
They essentially do the same thing. I'm thinking first one is better from the standpoint of "Write more code only if you have to" and the second one is better from readability aspect.
I'd use a switch statement with default case but I'm using a old version of JDK.. so I can't use it on Strings.
Which one is better?
switch
? Java7 exists. \$\endgroup\$