Java技巧——少用枚举类型
少用枚举类型
public enum StatusCodeAndPhrase {
OK("200 OK"),
MovedPermanently("301 Moved Permanently"),
BadRequest("400 Bad Request"),
NotFound("404 Not Found"),
VersionNotSupported("505 HTTP Version Not Supported");
private String CodeAndPharse;
StatusCodeAndPhrase(String CodeAndPharse)
{
this.CodeAndPharse = CodeAndPharse;
}
public String getCodeAndPharse()
{
return this.CodeAndPharse;
}
}
多用静态变量
public class Status {
public static final String OK = "200 OK";
public static final String MOVED_PERMANENTLY = "301 Moved Permanently";
public static final String BAD_REQUEST = "400 Bad Request";
public static final String NOT_FOUND = "404 Not Found";
public static final String HTTP_VERSION_NOT_SUPPORTED = "505 HTTP Version Not Supported";
原因:枚举类型调用的时候特别复杂!!!!