publicclassSimplifyIfElse{publicStringhandleQuestion(Stringtype,Stringdetail){if("A".equals(type)){return"call methodA to handle"+detail;}elseif("B".equals(type)){return"call methodB to handle"+detail;}elseif("C".equals(type)){return"call methodC to handle"+detail;}else{thrownewIllegalArg...
51CTO博客已为您找到关于java function 函数 消除 if else的相关内容,包含IT学习相关文档代码介绍、相关教程视频课程,以及java function 函数 消除 if else问答内容。更多java function 函数 消除 if else相关解答可以来51CTO博客参与分享和学习,帮助广大IT技术人实现成长和
publicclassSimplifyIfElse{publicStringhandleQuestion(Stringtype,Stringdetail){if("A".equals(type)){return"call methodA to handle"+detail;}elseif("B".equals(type)){return"call methodB to handle"+detail;}elseif("C".equals(type)){return"call methodC to handle"+detail;}else{thrownewIllega...
publicclassSimplifyIfElse{publicStringhandleQuestion(String type, String detail){if("A".equals(type)) {return"call methodA to handle"+ detail; }elseif("B".equals(type)) {return"call methodB to handle"+ detail; }elseif("C".equals(type)) {return"call methodC to handle"+ detail; }else...
} else { throw new IllegalArgumentException("invalid type: " + type); } } } 这种代码其实很常见的,使用起来也就是一行调用: 代码语言:java 复制 public static void main(String[] args) { assert new SimplifyIfElse().handleQuestion("B", "detail").equals("call methodB to handledetail"); ...