Java enumeration methods

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.