java enum 实例

package jp.gummy.bsns.platform.constants;


/**
* @author Administrator
* 用户状态
*/
public enum StatusEnum {

STUDENT(10,"学生"),

TEACHER(15,"职员"),

OTHER(22, "其他");

private int index;

private String name;

StatusEnum(int index,String name){
    this.index = index;
    this.name = name;
}

public static String getName(int index){
        for (StatusEnum item : StatusEnum.values()) {
      if (item.index == index) {
        return item.name;
      }
    }
        return "";
}

public static void main(String[] args) {
        System.out.println(StatusEnum.getName(10));
}
}

你可能感兴趣的:(java)