java枚举貌似没什么可说滴,其实还是有点意思
下面就是一个有一点复杂的java枚举的例子
//复杂的枚举类型
enum ETableType
{
String("Varchar"),
Int("Number"),
Date("Date"),
Boolean("Boolean"),
Float("Decimal");
private String dbType;
public String getDbType()
{
return dbType;
}
public void setDbType(String dbType)
{
this.dbType = dbType;
}
ETableType(String dbType)
{
this.dbType = dbType;
};
public String getDBEntityType(int length)
{
String name = this.name().toLowerCase();
if(name.equals("date") || name.equals("boolean"))
return dbType;//无需配接长度的类型
StringBuffer sb = new StringBuffer();
sb.append(dbType).append("(").append(length).append(")");
return sb.toString();
}
}