Couple of Key notes that I have noted are as followings:
- enums are implicitly final subclasses of java.lang.Enum that is inherited from java.lang.Object.
- As enums are implicitly final classes, so inheritance between enums or simple classes is not possible.
- If an enum is member of a class it is implicitly static.
- new keyword can never be used with enum.
- name() and valueOf() methods simply use the text of enum constant.
- Defualt implementation of toString() returns the name of the enum constant, but you can override its implementation.
- For enum constants equals() and == amount to the same thing and can be used interchangebly.
- enum constants are implicitly public, static and final
- The order of appearance of enum constants is called their NATURAL ORDER
- There is a built in method named as values() that returns the array of all enum constants.
- All instances of Enums are serializable by default. As Enums are subclasses of class java.lang.Enum, which implements the interface java.io.Serializable. If a class implements the interface java.io.Serialisable, its objects are serializable.
- Enums are compiled to a .class file.
- An enum can define a main method and it can be executed as a standalone application
- You can provide the abstract methods in the enum, but this abstract method needs to be implemented by all of the enum constants because we can not declare enum itself as abstract. Simply We cannot define abstract enums.
- Enums cannot be instantiated, we can only create the reference of an enum
- Enums may be used as a operand for the instanceof operator in the same way that it can be used by a class
- Enums can be used in switch statements.
- An enum can define more than 1 constructor (similar to a class) and its constructor can accept more than 1 method parameter. Please note we can not create the actual object using new like we do with classes.
- name() is a final method, which cannot be overridden. It returns the name of the enum constant, exactly as declared in its enum declaration.
- Constructors for an enum type should be declared as private. The compiler allows non
private declares for constructors, but this seems misleading to the reader, since new can
never be used with enum types.
- Constructor of enum can only be private or default. public and protected are not allowed with constructor of Enum.
- Enum can implement interface.
- Enums cannot be declared within a method!