The type Enum is imported by Java1.5, here are some of the notice about using Enum in Java
1. Enum is actually one interface
2. Consider Enum as one simple class with several pre-defined instance, so user can define his own variable and method in Enum. Also Enum can implement more than one interface.
3. user can define his own constructor in Enum, but note than do not define any public constructor, otherwise, it will expose interface for other to define Enum. But Enum is pre-defined.
4. Enum implements the Comparable interface by default
5. all the enum value is defined as public static final by default
6. in Enum, the value list should be defined at the first place
7. values() method return all the enum values, and oridinal() method return the order of one enum value
8. user can define seperate method for each enum value
for example:
public enum SeperateMethodEnum {
Spring{
public String toString(){
return "Spring";
}
},
Summer;
public String toString(){
return “toString”;
}
}
9. for enum value, user can define value attached to it
for example:
public enum ValueEnum {
Spring(1),
Summer(2),
Automn(3),
Winter(4);
ValueEnum(int value){
this.value = value;
}
private int value;
public int getValue(){
return value;
}
}