3

请任何人帮助我。我想将 Objective-c 枚举转换为 android 枚举,如下所示:

// Objective-c enum
===================
typedef enum{
  ab = 0,
  bc = 1,
  ca = 2
}PieceType;

// just print using android Logcat:
=================
Log("ab = ", ab+"");
Log("bc = ", bc+"");
Log("ca = ", ca+"");
================

Result: 
ab = 0;
bc = 1;
ca = 2;

想要将上面的枚举转换为 android 枚举但在打印时保持相同的结果。

4

2 回答 2

1

将来,请在询问之前尝试阅读参考资料Enum Types

这是示例:

public enum Example {
   AB(0), BC(1), CA(2);

   private int val;

   private Example(int c) {
       val = c;
   }

   public int getData() {
       return val;
   }
}

用法:

int value = Example.AB.getData();
于 2013-03-21T07:54:16.287 回答
1

也许这有帮助

public enum PieceType{
    AB(0), BC(1), CA(2);
    private int value;

    private Currency(int value) {
            this.value = value;
    }
};   

在这里给你一个链接:

http://javarevisited.blogspot.de/2011/08/enum-in-java-example-tutorial.html

于 2013-03-21T07:56:41.710 回答