1.第一种形式:
public interface PrealertConstants {
enum platformCodeEnum{
CAINIAO(1),
CLOSED(-5),
OFFLINE(2);
private int code;
private platformCodeEnum(Integer code){
this.code=code;
}
public int getCode(){
return code;
}
}
}
===========
调用:
if(PrealertConstants.platformCode_TaoBao.toString().equals(source)){
platCode=platformCodeEnum.CAINIAO;
}else{
platcode=PrealertConstants.platformCodeEnum.valueof(source);
}
第二种:
import lombok.Getter;
import lombok.Getter;
public enum JobExceptionEnum{
/* */
WJP("WJP","违禁品"),
CDCZ("CDCZ","超大,超重"),
XHJ("XHJ","销毁件"),
/**下架异常*/
XJYC("XJYC", "下架异常");
@Getter
@Setter
private String code;
@Getter
@Setter
private String name;
private JobExceptionEnum(String code,String name)
{
this.code=code;
this.name=name;
}
}
调用:
JobExceptionEnum.GQJ.getCode()
或者
JobExceptionEnum.GQG.getName();