+ 3
What is the use of enum keyword
2 Answers
+ 14
Enum serves as a type of fixed number of constants and can be used at least for two things
constant
public enum Month {
JANUARY, FEBRUARY, ...
}
This is much better than creating a bunch of integer constants.
creating a singleton
public enum Singleton {
INSTANCE
// init
};
You can do quite interesting things with enums, look at
http://javarevisited.blogspot.com/2011/08/enum-in-java-example-tutorial.html
Also look at the
http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html
-stackoverflow