枚举类型的使用

枚举

枚举是final,意味着它不能被继承,他的作用是用来限制输入的类型

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
public enum MaterialType{

UNDEFINED("Undefined", 0,"object"),

/** 枚举值码 */
private final String commandType;

/** 枚举描述 */
private final String desc;

/**
* 实现类
*/
private final String clazz ;


public static MaterialType find(int index) {
for (MaterialType c : MaterialType.values()) {
if (c.getIndex() == index) {
return c;
}
}
return null;
}
}