Package javaee. china. cxp;
Import org. junit. Test;
/**
* Function of enumeration: Some programs require a certain range of values instead of any data during runtime. JDK 5 used a custom class to solve this problem,
* After JDK 5, enumeration can be used directly.
* The New enum keyword in jdk5 is used to define an enumeration class.
* An enumeration can also contain constructors, fields, and methods.
*/
Public class Demo_7_emur {
@ Test
Public void test_6 (){
Print (Grade. );
Print2 (Grade2.A );
}
Public void print (Grade G ){
}
Public void print2 (Grade2G ){
}
/**
* The following method is replaced by the emur enumeration.
*/
Enum Grade2 {
A, B, C, D, E;
}
}
/**
* Jdk5 used custom classes to solve the problem.
* Privatize the Grade Constructor
* Provides a common static constructor.
*/
Class Grade {
Private Grade (){}
Public static final Grade A = new Grade ();
Public static final Grade B = new Grade ();
Public static final Grade C = new Grade ();
Public static final Grade D = new Grade ();
Public static final Grade E = new Grade ();
}