【发布时间】:2010-04-16 01:58:30
【问题描述】:
是否可以让枚举更改其值(从内部)?也许更容易理解我对代码的意思:
enum Rate {
VeryBad(1),
Bad(2),
Average(3),
Good(4),
Excellent(5);
private int rate;
private Rate(int rate) {
this.rate = rate;
}
public void increateRating() {
//is it possible to make the enum variable increase?
//this is, if right now this enum has as value Average, after calling this
//method to have it change to Good?
}
}
这是我想要实现的目标:
Rate rate = Rate.Average;
System.out.println(rate); //prints Average;
rate.increaseRating();
System.out.println(rate); //prints Good
谢谢
【问题讨论】: