如何在java中保存void方法的枚举值

时间:2013-12-18 07:28:40

标签: java

golog() eLogType.ADMINACTIONLOG中是枚举,在这种情况下我给出了一个字符串值,当调用golog(eLogType.ADMINACTIONLOG)时,我能够获取值,我需要保存其他变量中的值,在java中怎么可能?

public static void golog(eLogType e) 
{
     String formattedString=null;
     switch (e) {
     case LOG:
            formattedString ="#LOG - "+currentDateandTime +" File:"+new Throwable().fillInStackTrace().getStackTrace()[1].getClassName() +" Line:"+new                          
  Throwable().fillInStackTrace().getStackTrace()[1].getLineNumber();   
     break;
     case EXCEPTIONLOG:
formattedString ="#EXCEPTIONLOG - "+currentDateandTime +" File:"+new Throwable().fillInStackTrace().getStackTrace()[1].getClassName() +
 " Line:"+new Throwable().fillInStackTrace().getStackTrace()[1].getLineNumber();                     
      break;

    }                                                  
}

1 个答案:

答案 0 :(得分:1)

您可以通过以下方式获取值:

  • golog(eLogType.ADMINACTIONLOG.toString())
  • golog(eLogType.ADMINACTIONLOG.name())

e.g。有一个方法:

private void myMethod(eLogType type) {
    switch (type) {
    case ADMINACTIONLOG: {
        String asString = type.name();
    }
        break;

    default:
        break;
    }
}