In my previous article, I explained how and why to use enums
instead of the switch
/case
control structure in Java code. Here, I will demonstrate how to extend the functionality of existing enums
.
Introduction
Java enum
is a kind of a compiler magic. In byte code, any enum
is represented as a class that extends the abstract class java.lang.Enum
and has several static members. Therefore, enum
cannot extend any other class orenum
: there is no multiple inheritance.