我以前做symbian的时候,里面可以对其进行赋初值,比如以下这种:
public enum aa
{
    AAA = 0x1,
    BBB = 0x2,
    CCC = 0x4,
    DDD = 0x8
}在java中使用的时候发现使用赋值的话就出错了,是java的enum不能赋值,只能按顺序一个个来吗?
怎么做才能给他赋初值?

解决方案 »

  1.   

    public class EnumTest {    public static void main(String[] args) {
            System.out.println(EnumType.BBB.getValue());
        }
    }enum EnumType {
        AAA(0x1),
        BBB(0x2),
        CCC(0x4),
        DDD(0x8);
        
        private int value;
        
        private EnumType(int value) {
            this.value = value;
        }
        
        public int getValue() {
            return value;
        }
    }