枚举类的特性

枚举值最好全大写,可以有Get方法,但没有Set方法。

枚举类的用法

枚举型常量、带参数的枚举、枚举类重写方法

枚举型常量

public enum Season {  
    SPRING, SUMMER, FALL, WINTER;  
}

带参数的枚举

自定义的参数变量默认要使用 final 进行修饰

public enum Season {  
    SPRING("春"), SUMMER("夏"), FALL("秋"), WINTER("冬");  

		Season(String chineseName){
            this.chineseName = chineseName;
        }
  

    private final String chineseName;  
 
    public String getChineseName() {  
        return chineseName;  
    }  
  
}

枚举类重写方法

可以重写类本身的toString方法

public enum Season {  
    SPRING("春"), SUMMER("夏"), FALL("秋"), WINTER("冬");  

		Season(String chineseName){
            this.chineseName = chineseName;
        }
  

    private final String chineseName;  
 
    @Override
    public String toString() {
        return chineseName;
    }
  
}