[問題] switch 後面接 constant

作者: Arim (象山下智久)   2014-07-25 20:52:49
各位版友好
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,請問我這樣寫法是錯在哪裡呢?
謝謝
作者: ssccg (23)   2014-07-25 21:33:00
getValue是個method不是constant
作者: kkkmode (kkk)   2014-07-25 23:57:00
getValue能在編譯期間執行完嗎?

Links booklink

Contact Us: admin [ a t ] ucptt.com