在项目中使用Enum封装静态变量

  • 抛弃传统的public static final定义静态变量
  • 使用enum会让代码更加简洁,并且可以定义信息
public class Constant {
    
    

    public enum XX{
    
    
    // 变量
        XTYPE_BAST(1,"XXX"),XTYPE_SALE(0,"XXX");
        private int code;
        private String msg;

        XX(int code, String msg) {
    
    
            this.code = code;
            this.msg = msg;
        }
	// 定义get 方法,方便使用中获取信息
        public int getCode() {
    
    
            return code;
        }

        public String getMsg() {
    
    
            return msg;
        }
    }

}

猜你喜欢

转载自blog.csdn.net/JISOOLUO/article/details/105577345