问题
Can anyone assist me with an alternative to if-then-else statements for control flow? Or advise on a good article? From what I've seen, some use mapping or enums. Trouble I'm having is that I have multiple conditions i.e. if (condition1 && condition2 && condition3)...
and I need to do this for several permutations and all 3 variables need to be validated.
Please can someone point me in the right direction?
else if (String.Utils.isNotEmpty(payload.getKeyChange2TokenNumber()) &&
String.Utils.isEmpty(payload.getKeyChange1TokenNumber()) &&
String.Utils.isEmpty(payload.getKeyChange2TokenNumber())
{
So with no if-then-else statements, how can I implement a hashmap to determine what to return in place of the if-then-else statements?
return String.format(return value dependant on outcome of validation)
}
来源:https://stackoverflow.com/questions/61576470/alternative-for-an-if-then-else-statement