enum类型添加自定义的描述方法

来源:互联网 发布:linux设置自启动程序 编辑:程序博客网 时间:2024/06/05 22:34

在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());}}}