March 2019
Intermediate to advanced
242 pages
6h 21m
English
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, ...
Read now
Unlock full access