java之枚举

//简单枚举实例

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;
    }
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值