Use Enum to encapsulate static variables in the project

  • Abandon the traditional public static finaldefinition of static variables
  • Using enum will make the code more concise, and can define information
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;
        }
    }

}

Guess you like

Origin blog.csdn.net/JISOOLUO/article/details/105577345