【发布时间】:2016-08-28 17:48:08
【问题描述】:
我有一个Enum:
public enum Type {
ADMIN(1),
HIRER(2),
EMPLOYEE(3);
private final int id;
Type(int id){
this.id = id;
}
public int getId() {
return id;
}
}
如何通过 id 属性获得 Type 枚举?
【问题讨论】:
-
您可以迭代
Type值并查找您的id;或填写Map<Integer, Type>。 -
This might be exactly what you need.(除了你有一个
int id而不是String text。