An enumeration type is a basic data type, not a constructed data type, but a new type from jdk1.5, which is generally used to make global constants .
Characteristics:
1. It cannot have a public constructor This ensures that the client code has no way of creating an instance of an enum that can be used to write a singleton pattern.
2. All < Span style= "COLOR: #ff0000" The enumeration value is public, static, final 3. The enum contains the ToString method, so we call Color.Blue.toString () to return the string "Blue" by default.
Usage:1: string constant (also the most concise singleton mode):
Define public enum enumkey{ Message_update,message_delete,message_add;} Use EnumKey.MESSAGE_ADD.toString ();
2: Integral type constant
Define public enum EnumKey { message_update (1), Message_delete (2), Message_add (3); public int tag; EnumKey (int iTag) { this.tag = ITag; }} use int i =enumkey.message_add.tag;
3: string constant (the second method of presentation)
Define public enum EnumKey { message_update ("UPDATE"), Message_delete ("DELETE"), Message_add ("ADD"); Public String msg; EnumKey (String str) { this.msg = str; }} Use string s =enumkey.message_add.msg;
4: Add method
Define public enum EnumKey { message_update ("UPDATE", 1), Message_delete ("DELETE", 2), Message_add ("ADD", 3); Public String msg; public int tag; EnumKey (String str, int iTag) { this.msg = str; This.tag = ITag; } public static Boolean getmax (int flag) { return flag > 1? true:false; }} Use EnumKey.MESSAGE_ADD.getMax (2);
Summary:
'
Did you find anything yet?
Each instance of the enumeration contains parameters that are consistent with the parameters contained by the enumeration's constructor method
So you will find that in fact message_update ("UPDATE", 1) represents the meaning of EnumKey message_update=new EnumKey ("Update", 1), i.e.:
Public class EnumKey {public static String msg; public static int tag; Public EnumKey (String str, int iTag) { this.msg = str; This.tag = ITag; }} EnumKey message_update=new EnumKey ("UPDATE", 1);
Analysis of the meanings of enum-type enums