取的名字我有一个枚举类在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