19.4 The mystery of values()
By decompiling the enumeration class, values() is a static() method added by the compiler. The compiler marks the enumeration class (enum) as a final class, so the enum class cannot be inherited.
All enum classes inherit from the java.lang.Enum class. Since Java does not support multiple inheritance, your enum class cannot inherit other classes. However, when we create a new enum, we can implement one or more interfaces at the same time.
Like EnumSet, the order in which enum instances are defined determines their order in EnumMap.
Constant-specific methods.
Multiple dispatching.
Through the corresponding enum instance, we can call the methods on it. This is also often called table-driven code (note its similarity to the command pattern mentioned earlier).
chain of Responsibility.
ONE way is to use a constructor to initialize each enum instance and take a "set" of results as parameters. The two are put together to form a structure similar to a query table.
Related articles:
Java Programming Thought Learning Class (4) Chapter 17 - In-depth Discussion of Containers
Java Programming Thought Learning Class (5) Chapter 18-Java IO System
The above is the detailed content of Java Programming Thoughts Learning Class (6) Chapter 19 - Enumeration Type. For more information, please follow other related articles on the PHP Chinese website!