java枚举实例
实例一:
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;
}
}
}
实例四(带抽象方法的枚举):
public static void main(String[] args) {
System.out.println(OrderState.A.aaa());
}
public enum OrderState {
A{
public String aaa(){
return "优";
}
},
B{
public String aaa(){
return "良好";
}
},
C{
public String aaa(){
return "及格";
}
};
public abstract String aaa();
}
实例五(综合实例):
enum Grade{//class
感谢您的阅读,您的支持是我写博客动力。