標籤:
1、最古老的
//未處理public static final int PROCESS_STATUS_UNTREATED = 0;//已接收public static final int PROCESS_STATUS_ACCPECTED = 1;//已處理public static final int PROCESS_STATUS_PROCESSED = 2;
2、改進版的
public static final class PROCESS_STATUS{ //未處理 public static final int UNTREATED = 0; //已接收 public static final int ACCPECTED = 1; //已處理 public static final int PROCESSED = 2;}
3、枚舉版(好處顯而易見,既可以擷取code又能擷取漢字),以後定義常量採用此方法
public static enum PROCESS_STATUS implements KeyValueEnum{ UNTREATED(0,"未處理"), ACCPECTED(1,"已接收"), PROCESSED(2,"已處理"); private Integer code; private String desc; private PROCESS_STATUS(Integer key , String value){ this.code = key; this.desc = value; } @Override public Integer getCode() { return code; } @Override public String getDesc() { return desc; } }
調用方式:
//擷取編碼PROCESS_STATUS.UNTREATED.getCode();//擷取描述PROCESS_STATUS.UNTREATED.getDes();
JAVA中定義常量的3種方式