Enum Tricks: Two Ways to Extend Enum Functionality

In my previous article, I explained how and why to use enumsinstead of the switch/case control structure in Java code. Here, I will demonstrate how to extend the functionality of existing enums.

Introduction

Java enumis 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.