Sharper typing of enum constants

One of the two major goals of enhanced enums is to perform sharper type-checking for enums. At present, the type of all enum constants is the enum in which they are defined. Referring to our example enum, Size, this essentially means that the type of all of the enum constants (SMALL, MEDIUM, and LARGE) is Size, which is incorrect (as depicted in the following figure):

Although enum constants are allowed to define a constant specific class body, which includes variables and methods, the constant type is not sharp enough to allow for access to enum constant-specific values. Even in the case of generic enums, the static type of an enum constant is not sharp enough to capture the full type information of individual constants.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.14.82.217