关于一个字符串的问题
首先定义一个类,只有几个常量
public class ManipulationHabitus {
public static final String SUCCESS = "success "; //操作成功
public static final String FAILURE = "failre "; //操作失败
public static final String PWDMISTAKE = "pwdmistake "; //密码错误
public static final String USERNOEXIST = "usernoexist "; //用户不存在
public static final String USEREXIST = "userexist "; //用户存在
public static final String SQLERROR = "sqlerror "; //数据库错误
}
然后将放入HashMap中
hashMap.put( "ManipulationHabitus ", ManipulationHabitus.SUCCESS);
然后进行判断,不知道为什么,不能够这样进行判断.
switch ((String)hm.get( "ManipulationHabitus ")) {
case ManipulationHabitus.SUCCESS:
System.out.println(ManipulationHabitus.SUCCESS);
break;
case ManipulationHabitus.PWDMISTAKE:
System.out.println(ManipulationHabitus.PWDMISTAKE);
break;
case ManipulationHabitus.USERNOEXIST:
System.out.println(ManipulationHabitus.USERNOEXIST);
break;
case ManipulationHabitus.SQLERROR:
System.out.println(ManipulationHabitus.SQLERROR);
break;
}
请问这是为什么啊.
------解决方案--------------------Switch 不支持String
只能是整数类型的,如int,byte,char,...