除了这样做外,还有其它办法吗
public enum Test
{
    one(1), two(2), three(3);
    private Test(int value)
    {
        this.value = value;
    }
    private int value;
}然后这样用
switch (aenum.value)
{
    case 1: .....; break;
    case 2: .....; break;
}请问还有其它办法吗。

解决方案 »

  1.   

    switch只支持可以转成int型的,比如int、char,像你的枚举应该不行的
      

  2.   

    这样做的话如果元素的值改变了,那个switch那里的判断也要改了。
      

  3.   

    原来是这个意思啊,那修改一下就可以了啊switch (aenum.value)
    {
        case Test.one: .....; break;
        case Test.two: .....; break;
        ....
    }
      

  4.   

    学习中
    我怎么看不懂啊
    public enum Test 这个是什么意思?难道是java5新引进的?
    还有one(1), two(2), three(3);怎么个意思?
    然后switch (aenum.value)
    这个aenum是从哪里来的?
    烦请达人解释一下啊
    谢谢啊
    难道两个月没看java,我又落伍了。。
      

  5.   

    我在java world上问到一个方法把Test.one, Test.two, Test.three转换成1,2,3
    enum Test
    {
         one, two, three;
         public static int conv(Test t)
         {
    int i = 0;
    switch (t)
    {
    case one:
    i = 1;
    break;
    case two:
    i = 2;
    break;
    case three:
    i = 3;
    break;
    }
    return i;
          }
    }
      

  6.   

    然后这样:
    Test t = Test.two;
    int i = Test.conv(t);
    System.out.println(i);不知对你有没有用