Claudio De Sio Cesari’s Post

In Java, enum types are often introduced as just a list of constants. But they are actually much more powerful: they are real classes, with constructors, methods, and even different behavior for each constant. In this article I explore some lesser-known uses of enums that can make Java code more expressive and robust. ✍️ Stranger Things in Java: Enum Types Happy coding! ☕💻

Simply the best article on Java enums. It's complete, clear, and correct. I'll only add that enums prove that default access is not limited to package-private. Study this article, folks. It teaches more than just facts about enums. It teaches how to think in Java, or really any programming language. It teaches how to architect with inheritance and polymorphism. It teaches about programming for safety. It even teaches how best to write a singleton type in Java.

Very good article. The only thing I sort of miss is a note that even though enums are real classes and can do anything, then any added functionality should enhance the enum functionality and not add something unrelated to the enum functionality. All your examples are fine. But without the note then some may be tempted to become "creative".

See more comments

To view or add a comment, sign in

Explore content categories