Java enum usage

Source: Internet
Author: User

Public enum Type {
IN ("input parameters "),
OUT ("output parameter "),
VAR ("variable ");
 
 
 
// Define the constructor with parameters so that you can write IN ("....")
Private String des;
Type (String des)
{
This. des = des;
}
Public String getDesc ()
{
Return des;
}
}
 
 
 
 
Public enum State {
ON {
 
@ Override
String getInfo (){
Return "open ";
}
}, OFF {
 
@ Override
String getInfo (){
// TODO Auto-generated method stub
Return null;
}

};
// Extend an abstract method for each value
Abstract String getInfo ();
};
 
 
Java prototype of enum:
Public final class Type extends Enum
{
 
Public static final Type IN;
Public static final Type OUT;
Public static final Type VAR;
Private String des;
Private static final Type ENUM $ VALUES [];
 
Private Type (String s, int I, String des)
{
Super (s, I );
This. des = des;
}
 
Public String getDesc ()
{
Return des;
}
 
Public static Type [] values ()
{
Type atype [];
Int I;
Type atype1 [];
System. arraycopy (atype = ENUM $ VALUES, 0, atype1 = new Type [I = atype. length], 0, I );
Return atype1;
}
 
Public static Type valueOf (String s)
{
Return (Type) Enum. valueOf (com/sunline/flow/ide/project/navigator/model/Type, s );
}
 
Static
{
IN = new Type ("IN", 0, "input parameter ");
OUT = new Type ("OUT", 1, "output parameter ");
VAR = new Type ("VAR", 2, "variable ");
ENUM $ VALUES = (new Type [] {
IN, OUT, VAR
});
}
}

 

Author: lizhensan"
 

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.