Alternative for an if then else statement

假如想象 提交于 2020-06-01 07:38:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!