我有两个Java类:
public abstract class IconNames {
/**
*
*/
public static final String ButtonFett = java.util.ResourceBundle.getBundle("recources/buttonproperties").getString("fett");
}
并且。
public class EditorPanelActionListener implements ActionListener{
.
.
.
String buttonText = e.getActionCommand();
switch(buttonText)
{
case IconNames.ButtonFett: //Error: constant string expression required
replace(XmlTags.BOLD);
break;
}
.
.
.
}
编辑器面板操作监听器触发了错误信息"需要常量字符串表达式",问题出在哪里呢?
谢谢!
switch
语句的情况必须是编译时常量。而您的变量只能在运行时评估。 - jlordo