0
我有一個枚舉類型枚舉吸氣返回錯誤值
public enum Type {
A("abc1", "desc1"),
B("abc2", "desc2"),
C("abc3", "desc3"),
D("abc4", "desc4"),
E("abc5", "desc5");
private String value;
private String description;
private Type(String value, String description) {
this.value = value;
this.description = description;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
我通過下面的代碼
Type[] type = Type.values();
for (int i = 0; i < type.length; i++) {
System.out.println(type[i].getValue());
}
得到枚舉值這個代碼在服務器上運行。對於幾天它運行良好,這代碼的輸出如下:
abc1
abc2
abc3
abc4
abc5
但經過幾天的輸出變爲
abc1
abc2
abc1
abc4
abc5
如果我打印的說明,然後他們總是正確的。
我無法弄清楚爲什麼Type.getValue()可以枚舉枚舉值A的返回值值C.
「但幾天後,輸出變爲」 - 這讓我笑:)是否有其他正在運行的線程的地方? – Maroun
可變枚舉感覺像是一個非常糟糕的主意。使'價值'最終,移除setter。 –
http://stackoverflow.com/questions/3820149/enum-values-is-an-order-of-returned-enums-deterministic –