1、    目的
简单认为:满足一些需求
2、    定义、使用
public enum SexEnum {
    male(1),female(0);    
    private final int value;    
    private SexEnum(int value){
        this.value = value;
    }
    public int getValue(){
        return this.value;
    }
}
public class TestSexEnum {
    /*
     * @param args
     */
    public static void main(String[] args) {
        System.out.println(SexEnum.male.getValue());
        for (SexEnum item:SexEnum.values()){
            System.out.println(item.toString()+item.getValue());
        }
    }
}
3、与类/接口相比
=与类相同,不同的地方就是写法不一样(enum比较简单,但是写法比较陌生)
=同样可以添加方法,属性
=enum不能继承类(包括继承enum),只能实现接口,类无此限制(除非用final来限制)。在这个方面,enum更像interface
=enum只支持public和[default] 访问修饰,class支持比较丰富
=可以与下面的类比较一下,定义比较相似
Public class Sex{
    Public static final Sex male = new Sex(1);
    Public static final Sex female = new Sex(0);
    Private Sex(int value){
        This.value = value;
}
Public int getValue(){
    Return this.value;
}
}
=调用比较相似
SexEnum.male.getValue()
Sex.male.getValue()

总结:其实完全能够用class替代enum,个人认为enum是早期面向过程中,简单数值枚举集合的一种表示,在java中对enum进行了扩展,让它只具有类的部分能力,导致结构不清晰,在java中进入enum有画蛇添足的感觉.
       更为重要的是,我们在进行设计的时候引入enum非常容易偏离OO思想,进入以数据或者过程为中心的路子
--------------------------------------------------------------------------------------------
MyDemo:
public enum TrustPassMember {

  ETTrustPass(128479), // 128479
  PersonTrustPass(228479), // 228479
  MarketTrustPass(328479); // 328479

   private final int value;

   private TrustPassMember( int value) { //定义无参的构造函数
     this.value = value;
  }

   public int getValue() {
     return this.value;
  }
}
获取enum中对应类型的值:
TrustPassMember. ETTrustPass.getValue()

-----------------------------------------------------------------------------------------
刚在导入一个maven的工程时,出现了编译不兼容的情况,出现了enum之类的都不可以用,这主要是使用了jdk5.0之前的编译环境,而jdk1.5之前的版本的编译环境对jdk1.5之后的是编译不通过的。
project工程名->Properties->Java Compiler->Compiler compilance level使用1.5以上的
且勾上‘use default compliance settings’

 
 
   
  1. public enum TipLocale { 
  2.  
  3.     en_US, 
  4.  
  5.     zh_TW, 
  6.  
  7.     es_ES, 
  8.  
  9.     ru_RU, 
  10.  
  11.     pt_PT, 
  12.  
  13.     it_IT, 
  14.  
  15.     de_DE, 
  16.  
  17.     fr_FR, 
  18.  
  19.     ko_KR, 
  20.  
  21.     ja_JP, 
  22.  
  23.     ar_SA; 
  24.  
  25.     public static TipLocale getEnum(String value) { 
  26.         for (TipLocale tipLocale : values()) { 
  27.             if (tipLocale.name().equals(value)) { 
  28.                 return tipLocale; 
  29.             } 
  30.         } 
  31.         return null
  32.     } 
  33.