如何在Java中使用SWITCH CASE语句中的函数/方法
我有3种类型的数组:如何在Java中使用SWITCH CASE语句中的函数/方法,java,Java,我有3种类型的数组: ControlType ControlName ControlValue 当控件类型为“ClickButton”时,我必须传递相应的ControlName和ControlValue 代码: 在switch语句中只能使用常量(最终变量)和文本 public static final String MY_CONST = "foo"; public static int getMonthNumber(String ControlType) { int ControlVa
ControlType
ControlName
ControlValue
当控件类型为“ClickButton”时,我必须传递相应的ControlName和ControlValue
代码:
在switch语句中只能使用常量(最终变量)和文本
public static final String MY_CONST = "foo";
public static int getMonthNumber(String ControlType) {
int ControlValue = 0;
int ControlName = 0;
if (ControlType == null) {
return ControlValue;
}
switch (ControlType) {
case MY_CONST: // this will work
break;
case "ClickButton":
return ControlType(ControlValue, ControlName);
}
return ControlValue;
}
private static int ControlType(int controlValue, int controlName) {
// TODO Auto-generated method stub
return 0;
}
另外,请阅读for Java。您不需要(也不能在
返回后直接放置中断
,因为它是不可访问的。break
将永远不会被点击,因为该方法已返回。ClickButton
是编译时常量字符串吗?@khelwood新用户似乎只会提问而不会回答!!!!是的..ClickButton是一个字符串…它是在web上单击按钮的通用方法page@GopinathRaviClickButton
要么是字符串,要么是方法——不能两者都是!
public static final String MY_CONST = "foo";
public static int getMonthNumber(String ControlType) {
int ControlValue = 0;
int ControlName = 0;
if (ControlType == null) {
return ControlValue;
}
switch (ControlType) {
case MY_CONST: // this will work
break;
case "ClickButton":
return ControlType(ControlValue, ControlName);
}
return ControlValue;
}
private static int ControlType(int controlValue, int controlName) {
// TODO Auto-generated method stub
return 0;
}
I simplified like below:
`import resources.StringSwitchDemoHelper;
/**
* Description : Functional Test Script
* @author IBM
*/
public class StringSwitchDemo extends StringSwitchDemoHelper
{
public static String getControlValue(String controlType) {
String controlValue = null;
String controlName = null;
if (controlType == null) {
return controlValue;
}
switch (controlType) {
case "Html.INPUT.text":
return EnterText (controlName,controlValue);
}
return controlValue;
}
public static String EnterText(String controlName, String value)
{
TextGuiTestObject textObj = findList(controlName);
if (textObj != null) {
textObj.setText(value);
} else {
throw new ObjectNotFoundException();
}
return value;}
}`
Still it is not working!!