枚举的使用可以增加代码可读性,提前把需要已确定的信息实例化之后不用重复new对象。
package com.atguigu.common.constant;
public class WareConstant {
public enum PurchaseStatusEnum{
// 具体实例
CREATED(0,"新建"),
ASSIGNED(1,"已分配"),
RECEIVE(2,"已领取"),
FINISH(3,"已完成"),
HASERROR(4,"有异常");
// 每个实例包含的属性
private int code;
private String msg;
// 构造方法
PurchaseStatusEnum(int code,String msg){
this.code = code;
this.msg = msg;
}
// 对外提供获取某个实例属性的方法
public int getCode() {
return code;
}
public String getMsg() {
return msg;
}
}
public enum PurchaseDetailStatusEnum{
CREATED(0,"新建"),
ASSIGNED(1,"已分配"),
BUYING(2,"正在采购"),
FINISH(3,"已完成"),
HASERROR(4,"采购失败");
private int code;
private String msg;
PurchaseDetailStatusEnum(int code,String msg){
this.code = code;
this.msg = msg;
}
public int getCode() {
return code;
}
public String getMsg() {
return msg;
}
}
}