参见英文答案 >
Using Integer in Switch Statement 6个
我正在为我的Android应用程序在java中编写一些简单的代码,我得到了这些错误.
case表达式必须是常量表达式,而private static final Integer是常量
private static final Integer INVALID_USER = 901;
private static final Integer SENDING_FAILED = 902;
private static final Integer OK = 903;
/*
*
* And some more project related declaration...
*
*/
switch (responseCode){
case INVALID_USER:
// logout
break;
case SENDING_FAILED:
//resend request
break;
case OK:
break;
}
这是因为我使用了Integer Type,然后我将类型更改为int并解决了问题