在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;
}
}
答案 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;
}
}