2012-02-03 141 views
0

我将尝试使用下面的代码... 我使用的枚举类是枚举类型转换成int

public enum AccountType { 
     kAccountTypeAsset(0x1000), 
     kAccountTypeAssetFixed(0x1010), 

     private int value; 
     private AccountType(int value) 
     { 
     this.value = value;  
     } 
     public int getValue() 
     { 
      return value; 
     } 
    } 

    public AccountType accountType = kAccountTypeAsset; 
     integerToDB(accountType); 
... 

/*************************/ 

public Object integerToDB (Integer i) 
    { 
    if(i == -1) 
    { 
     return null; 
    } 
    return i; 
    } 

如何使用

ACCOUNTTYPE

作为整数。

+1

是不是你的getValue()方法是什么? – 2012-02-03 05:38:55

回答

2

integerToDB(accountType.getValue());

1

由于您的枚举已实施getValue方法,因此您可以使用accountType.getValue()来获取存储在accountType中的整数值。