java 枚举的简单应用。

枚举,就是保存着原始的《key,value》 在代码中会经常用到。为了不坑自己,记录一下笔记

package com.fortunedr.common.constant;

public enum AppleType {
    appleType1(1,1),
    appleType2(2,12);
    
    private AppleType(int index,int months){
        this.index=index;
        this.months=months;
    }
    
    private int index;
    private int months;
    
    
    public static int getMonths(int index) {
        for(AppleType apple:AppleType.values())
        {
            if(apple.getIndex() == index){
                return apple.getMonths();
            }
        }
        return 0;
    }
    public int getIndex() {
        return index;
    }
    public void setIndex(int index) {
        this.index = index;
    }
    public int getMonths() {
        return months;
    }
    public void setMonths(int months) {
        this.months = months;
    }
    
    
}