//简单枚举实例
public class demo2 {
public enum color{
red,blue,yellow
};
public static void main(String[] args) {
color co = color.red;
switch (co) {
case red:
co=color.blue;
break;
case blue:
co=color.yellow;
break;
default:
break;
}
System.out.println(co);
}
//向枚举中添加新方法
package com.zxiao;
/**
* 向枚举中添加新的方法
* @author Administrator
*
*/
public enum color {
//使用括弧定义枚举,枚举必须定义在前面
RED("红色", 1), GREEN("绿色", 2), BLANK("白色", 3), YELLO("黄色", 4);
//定义变量
private String name;
private int index;
//构造器
private color(String name, int index) {
this.name = name;
this.index = index;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
//覆盖方法
public String toString(){
return this.index+"_"+this.name;
}
public static void main(String[] args) {
for (color co : color.values()) {
System.out.print(co.name);
System.out.print("\t");
System.out.println(co.index);
}
//获取枚举实例
color x = color.RED;
System.out.println(x.toString());
}
public enum FeedbackTypeEnum { 全部(-1, "全部"), 查看简历(0, "查看简历"), 查看联系方式(1, "查看联系方式"), 已发面试通知(2, "已发面试通知"), 已发offer(3, "已发offer"), 已拒绝(4, "已拒绝"); private Integer code; private String desc; private static Map<String, FeedbackTypeEnum> map = new HashMap<>(); static { for (FeedbackTypeEnum temp : FeedbackTypeEnum.values()) { map.put(temp.getCode() + "", temp); } } public static FeedbackTypeEnum getFeedbackTypeEnumByCode(Integer code) { for (FeedbackTypeEnum eachObj : FeedbackTypeEnum.values()) { if (eachObj.getCode().equals(code)) return eachObj; } return null; } FeedbackTypeEnum(Integer code, String desc) { this.code = code; this.desc = desc; } public Integer getCode() { return code; } public void setCode(Integer code) { this.code = code; } public String getDesc() { return desc; } public void setDesc(String desc) { this.desc = desc; } public static Map<String, FeedbackTypeEnum> getAllMap() { return map; } }