public enum PlayerType {
ANONYMOUS(1, "AnonymousPatron"),
PATRON(2, "Patron"),
UNREGISTERED(3, "UnregisteredPlayer");
private int code;
private String description;
private static final Map<Integer, PlayerType> codeToEnum = new HashMap<Integer, PlayerType>();
static {
for (PlayerType PlayerType : values()) {
codeToEnum.put(PlayerType.getCode(), PlayerType);
}
}
PlayerType(int code, String description) {
this.code = code;
this.description = description;
}
public int getCode() {
return code;
}
public String getDescription() {
return description;
}
public static PlayerType fromCode(int code){
return codeToEnum.get( code );
}
}
Emun 简单实例
最新推荐文章于 2025-10-09 10:18:16 发布
本文介绍了一个名为PlayerType的枚举类型的实现细节。该枚举包含三种玩家类型:匿名玩家(ANONYMOUS)、注册玩家(PATRON)和未注册玩家(UNREGISTERED)。通过静态映射的方式实现了从整数代码到枚举类型的转换。
447

被折叠的 条评论
为什么被折叠?



