首页 > 代码库 > Java 枚举类
Java 枚举类
public enum Season2 implements Info{
spring("春天","春风又路江南岸"),
summer("夏天","映日荷花别样红"),
autumn("秋天","秋水共长天一色"),
winter("冬天","千树万树梨花开");
final String seasonName;
final String seasonDesc;
private Season2(String seasonName, String seasonDesc) {
this.seasonName = seasonName;
this.seasonDesc = seasonDesc;
}
//获取枚举类对象的信息
@Override
public String getInfo() {
switch(this){
case spring:return "a";
case summer:return "b";
case autumn:return "c";
case winter:return "d";
}
return null;
}
//该方法的另一种实现
public enum Season2 implements Info{
spring("春天","春风又路江南岸"){
@Override
public String getInfo() {
return "A";
}
},
summer("夏天","映日荷花别样红"){
//获取枚举类对象的信息
@Override
public String getInfo() {
return "A";
}
},
autumn("秋天","秋水共长天一色"){
@Override
public String getInfo() {
return "A";
}
},
winter("冬天","千树万树梨花开"){
@Override
public String getInfo() {
return "A";
}
};
final String seasonName;
final String seasonDesc;
private Season2(String seasonName, String seasonDesc) {
this.seasonName = seasonName;
this.seasonDesc = seasonDesc;
}
}