代码如下:
enum Status {
STATUS_OPEN(10),
STATUS_STARTED(11),
STATUS_INPROGRESS(12);
private final int status;
Status(int aStatus) {
this.status = aStatus;
}
public int getStatus() {
return this.status;
}
}
class StatusTest3 {
public static void main(String[] args) {
for (Status stat : Status.values()) {
System.out.println(stat + " value is " + stat.getStatus());
}
}
}
Status.values()
返回什么?
输出是:
STATUS_OPEN value is 10
STATUS_STARTED value is 11
STATUS_INPROGRESS value is 12
最佳答案
http://docs.oracle.com/javase/7/docs/api/java/lang/Enum.html
All the constants of an enum type can be obtained by calling the implicit public static T[] values() method of that type.
关于java - 有人能解释一下这个关于枚举的程序在java中是如何工作的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19218076/