取的名字我有一個枚舉類在Java中如下如何從枚舉在Java
public enum SMethod {
/**
* LEAVE IN THIS ORDER
*/
A (true, true, true,false),
B (true, true, false,false),
C (true, true, false,false),
D (false, false, false)
}
另一類具有以下方法
private String getSMethod(boolean isSds) {
if (isClsSds)
return "A";
else
return "B";
}
目前,該方法返回硬編碼值,但字符串。但我想使用SMethod枚舉來返回它。我寫它如下:
private SMethod getSMethod(boolean isSds) {
if (isClsSds)
return SMethod.A;
else
return SMethod.B;
}
但我的需要是這種方法應該retu String。
SMethod.A.name()應該給你的字符串。 – 2013-04-22 07:43:17