Skip to content
Advertisement

Why would an Enum implement an Interface?

I just found out that Java allows enums to implement an interface. What would be a good use case for that?

Advertisement

Answer

Enums don’t just have to represent passive sets (e.g. colours). They can represent more complex objects with functionality, and so you’re then likely to want to add further functionality to these – e.g. you may have interfaces such as Printable, Reportable etc. and components that support these.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement