如何在Java中使用SWITCH CASE语句中的函数/方法
我有三种类型的数组:
ControlType
ControlName
ControlValue
当控件类型为“ClickButton”时,我必须传递相应的ControlName和ControlValue
代码:
public class StringSwitchDemo extends StringSwitchDemoHelper
{
public static int getMonthNumber(String ControlType) {
int ControlValue = 0;
int ControlName = 0;
if (ControlType == null) {
return ControlValue;
}
switch (ControlType.toString()) {
case ClickButton:
return ControlType(ControlValue, ControlName);
break;
}
return ControlValue;
}
private static int ControlType(String controlValue, String controlName) {
// TODO Auto-generated method stub
return 0;
}
}
# 1 楼答案
在switch语句中只能使用常量(最终变量)和文本
另外,请阅读Java的naming conventions