"It is a compile-time error if an enum declaration has the modifier abstract or final.
An enum declaration is implicitly final unless it contains at least one enum constant that has a class body (§8.9.1)."
Thank you very much, now I understand.
The misunderstanding was that English is not my mother tongue and I translated in my head: "enum can be thought of as a final class".
posted 3 weeks ago
Quoting from the JLS link given earlier.
Paul Clapham wrote:. . . An enum declaration is implicitly final unless it contains at least one enum constant that has a class body (§8.9.1)."
I think I misunderstood that bit about implicitly final at first. I thought that meant that an enum with class bodies can be extended by a different XXX.java file or compilation unit. I think it actually means that enums with class bodies extend themselves. They cannot be extended elsewhere. The constants with class bodies look like instances of anonymous classes. I don't know whether they really are anonymous classes.
If you write a compilation unit extending an enum with class bodies for every constant, e.g. the Operation enum from the Java™ Language Specification (=JLS), you will see you get a compiler error.
If you go through the first JLS link I gave you, you will find out why you can't write enum XYZ extends...
CAUTION! Do not touch the blades on your neck propeller while they are active. Tiny ad:
Devious Experiments for a Truly Passive Greenhouse!