我需要通過int來查找枚舉。枚舉是folows:通過常量特定數據在枚舉常量內查找
public enum ErrorCode{
MissingReturn(1,"Some long String here"),
InvalidArgument(2,"Another long String here");
private final int shortCode ;
private final String detailMessage;
ErrorCode(shortCode ,detailMessage){
this.shortCode = shortCode ;
this.detailMessage= detailMessage;
}
public String getDetailedMessage(){
return this.detailMessage;
}
public int getShortCode(){
return this.shortCode ;
}
}
現在是需要有一個將採取int
代碼和應該返回我屬於存儲在Enum
.Passing一個代碼的String
消息的查找方法「1」應該返回字符串「這裏有一些長字符串」。什麼是實現此功能的最佳方式?
public static String lookUpMessageFromCode(int code){
}
P.S:類EnumMap
是否適用於這種用例?如果是,請讓我知道爲什麼?
我已經看到了這問(並回答)多次在過去幾天。 – NPE 2013-03-16 08:37:42
@NPE任何指針? – Geek 2013-03-16 08:38:47
短碼值是否爲任意值(無特定碼型),還是隻有1,2,3等? – Bohemian 2013-03-16 10:32:22