在Think in java中的基础上做了一些调整
package enumerated;
//: enumerated/OzWitch.java
// The witches in the land of Oz.
import static net.mindview.util.Print.*;
public enum OzWitch {
// Instances must be defined first, before methods:
WEST("西"), NORTH("北"), EAST("东"), SOUTH("南");
private String description;
private OzWitch(String description) {
this.setDescription(description);
}
/**
* @param description the description to set
*/
private void setDescription(String description) {
this.description = description;
}
/**
* @return the description
*/
public String getDescription() {
return description;
}
public static void main(String[] args) {
for(OzWitch o : OzWitch.values()){
print(o + ":" + o.getDescription());
}
}
}
本文介绍了一个基于枚举类型的示例程序,该程序定义了OzWitch枚举类,通过构造函数和方法来设置和获取描述信息,并展示了如何遍历枚举的所有实例。
1313

被折叠的 条评论
为什么被折叠?



