作者Arim (Arim5566)
看板java
标题[问题] switch 後面接 constant
时间Fri Jul 25 20:52:49 2014
各位版友好
enum Choice {
EDITPROFILE(0),MAILFOLDER(1),SENDMESSAGE(2),LOGOUT(3);
private final int value;
private Choice(int value){
this.value=value;
}
public int getValue(){
return this.value;
}
};
public class Main{
...
public void onItemClick(int position) {
switch(position){
case choice.EDITPROFILE.getValue():
break;
case choice.MAILFOLDER.getValue():
break;
case choice.SENDMESSAGE.getValue():
break;
case choice.LOGOUT.getValue():
break;
}
}
编译器告诉我 case 後面必须接 constant,请问我这样写法是错在哪里呢?
谢谢
--
~宅男的四个徵兆~
∠□ ○ ! * \○/ ★ (○ ?
╦╦└□ " ○□═ □ □>
║║√√ ╦══╦ ∥ |\
一回家就上PTT 每天想正妹 以当好人为乐 忘记正妹亏欠自己
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 49.159.133.241
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/java/M.1406292772.A.FB9.html
1F:→ ssccg:getValue是个method不是constant 07/25 21:33
哈,了解
※ 编辑: Arim (49.159.133.241), 07/25/2014 23:39:42
2F:推 kkkmode:getValue能在编译期间执行完吗? 07/25 23:57