intで列挙型を検索する必要があります。列挙型は次のとおりです。
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 ここで、コードを取得し、に格納されているそのコードStringに関連するメッセージを返すルックアップ メソッドが必要です。 「1」Enumを渡すと、文字列「Some long String here」が返されます。この機能を実装する最良の方法は何ですか?
public static String lookUpMessageFromCode(int code){
}
PS: クラス EnumMapはこの種のユースケースに役立ちますか? はいの場合、理由を教えてください。