Java enumeration methods
Constant definitions usually include database tables, configuration files, JAVA static constants, and enumeration classes.
1. Database Table Method
create table t_USER( PK_ID NUMBER(10) not null, SEX VARCHAR2(255) check (SEX in(0,1)), USERNAME VARCHAR2(255))
The sex field limits the value of the field to 0 and 1. Here we assume that 0 represents male 1 represents female.
2. Configuration File
user_Type_man=0user_type_women=1
JAVA static variable defined in the User class
public final static int man=0;public final static int woman=1;
Enumeration type
Package liuc;/*** data type enumeration * @ author Administrator **/public enum DataTypeEnum {WOMAN (1), MEN (2); // construct enumeration values, for example, RED (255, 0, 0) private DataTypeEnum (int sexType) {this. sexType = sexType;} public String toString () {// overwrite the toString () return sexType "";} private int sexType;} of the Enum parent class ;}
In practice, we generally use the combination of enumeration types and databases to ensure program consistency and program readability. Of course, this is only applicable to fixed type values.
But for those types that frequently change or can be manually added. You still need a field value to represent it.
Java Enumeration type problems
Basically, there is no difference.
Java enumeration data type problems
This article is clear
Www.cnblogs.com/..3.html