码迷,mamicode.com
首页 > 编程语言 > 详细

java枚举实例

时间:2016-06-15 12:17:00      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:

实例一:

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;
}
}
}

java枚举实例

标签:

原文地址:http://www.cnblogs.com/chenweichu/p/5586892.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!