public class Topic { private TopicStatus status = TopicStatus.NORMAL;// 状态(是否锁定) public TopicStatus getStatus() {
return status;
}
public void setStatus(TopicStatus status) {
this.status = status;
}
public static enum TopicStatus {
NORMAL("正常"), LOCKED("锁定"); private final String label; private TopicStatus(String label) {
this.label = label;
} /** 显示的名称 */
public String getLabel() {
return this.label;
} /** 所代表的值 */
public String getValue() {
return this.name();
};
}}定义了TopicStatus,然后把它作为一个变量类型。这是什么用法?
不理解
return status;
}
public void setStatus(TopicStatus status) {
this.status = status;
}
public static enum TopicStatus {
NORMAL("正常"), LOCKED("锁定"); private final String label; private TopicStatus(String label) {
this.label = label;
} /** 显示的名称 */
public String getLabel() {
return this.label;
} /** 所代表的值 */
public String getValue() {
return this.name();
};
}}定义了TopicStatus,然后把它作为一个变量类型。这是什么用法?
不理解
这样这2个实例就可以在程序里被引用了。
在一个类中定义一个枚举,而且这个枚举还是public,static.
你把它看成类就行了,我自己对枚举的理解就是已经限定了取值范围的类。