안녕하세요, 아래에 표시된 것처럼 내부 클래스에있는 enum 값에 액세스하려고합니다. 그러나 내가 얻는 것은 값이 아니라 키입니다. . 내 응용 프로그램의 필요성은 내가 반영을 통해이 값에 액세스해야합니다. 출력 대신 "12"
로 내가 "AllEven"
얻고이 일에Reflection을 통해 내부 클래스에있는 enum의 값을 가져 오는 방법
public class Test{
static class TwelveByTwentyFour {
public static enum BET_TYPE_NAME {
Direct12(12),AllOdd(12),AllEven(12), First12(12), Last12(12);
private int value;
BET_TYPE_NAME(int value){
this.value = value;
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
}
}
public static String getBetTypeLength(String gameName,String betType) throws ClassNotFoundException, IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException{
return Class.forName(Test.class.getCanonicalName()+"$"+gameName+"$"+"BET_TYPE_NAME").getDeclaredField(betType).get(null).toString();
}
public static void main(String[] args) throws IllegalArgumentException, SecurityException, ClassNotFoundException, IllegalAccessException, NoSuchFieldException {
System.out.println(getBetTypeLength("TwelveByTwentyFour", "AllEven"));
}
}
. 아무도 내가 값을 얻을 수있는 방법을 말해줌으로써 나를 도울 수 있습니까?