Effective Enums — Part 1
Java 5 enums are one of the language’s most underappreciated features. Joshua Bloch devotes significant coverage to them in Effective Java for good reason — they’re more powerful than most developers use them.
This is the first in a series exploring enums in depth.
The Scenario
Consider a Loan type that needs to:
- Return the interest rate for a given loan category
- Return the maximum repayment period
- Check eligibility based on age and credit score
Java 5 makes this clean with enum constants that carry behavior.
The Java 1.4 Problem
For developers stuck on Java 1.4 — which predates native enum support — the same pattern required a workaround:
- Create a dedicated interface that defines the enum contract
- Implement the loan constants using static final instances of a class that implements the interface
This is the classic typesafe enum pattern described by Bloch before Java had language-level enum support.
Phew — it works, but it’s significantly more boilerplate than the Java 5 version.
Why This Matters
Understanding the Java 1.4 workaround isn’t just historical trivia. It reveals why Java 5 enums were designed the way they are — as full classes, not just integer constants. That design decision is what makes Java enums genuinely useful for modeling domain concepts rather than just mapping names to numbers.
More in Part 2.