- Generated constructor is private, there’s no way to create new enum instance if not list in the class.
- enum values are static fields of the class.
- enum class extends abstract class Enum<T extends Enum<T>> after compilation.
- enum could be used to define constant class as its constructor is private.
public enum EnumColor {
Yellow("Yellow"), Red("Red");
private String color;
EnumColor(String color) {
this.color = color;
}
public String getColor() {
return color;
}
public static void main(String ...args) {
System.out.println(Yellow.getColor());
}
}
enum Constants {
;
public static String CONF = "app.conf";
public static int ARRAY_CAP = 16;
}