tôi có các lớp học 2 Java:Java Lỗi: biểu hiện chuỗi liên tục đòi hỏi
public abstract class IconNames {
/**
*
*/
public static final String ButtonFett = java.util.ResourceBundle.getBundle("recources/buttonproperties").getString("fett");
}
và
public class EditorPanelActionListener implements ActionListener{
.
.
.
String buttonText = e.getActionCommand();
switch(buttonText)
{
case IconNames.ButtonFett: //Error: constant string expression required
replace(XmlTags.BOLD);
break;
}
.
.
.
}
Các EditorPanelActionListener lửa lỗi "biểu hiện chuỗi liên tục yêu cầu", whats vấn đề?
Cảm ơn!
Câu trả lời ngắn: Các trường hợp câu lệnh 'switch' phải là hằng số thời gian biên dịch. Biến của bạn chỉ có thể được đánh giá khi chạy. – jlordo
có thể e.getActionCommand() trả về enum thay vì một String không? – rajesh