实例一:
public enum OrderOption {
ASC,
DESC;
}
实例二(带参数构造函数):
public enum OrderOption {
ASC("ASC"),
DESC("DESC");
String type;
OrderOption(String type){
this.type = type;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
实例三(枚举公共方法):
public static void main(String[] args) {
System.out.println(SeasonEnum.getSeason("spring"));
}
public enum SeasonEnum {
spring, summer, autumn, winter;
public static SeasonEnum getSeason(String position) {
if ("spring".equals(position)){
return spring;
}else if("summer".equals(position)){
return winter;
}else if("autumn".equals(position)){
return autumn;
}else{
return winter;
}
}
}