Thursday, June 16, 2011

Effective Enums - 1

I'm planning to start a small series of one of my favorite inclusions in Java 5 - Enums. Joshua Bloch in his book Effective Java has dedicated an entire chapter on the same. This series will also be loosely based on the same.

In short, I want to have a Loan constant that can help me get the interest rate, maximum repay period and to check if one is eligible provided you enter the age and credit score. Here is my implementation in Java 5 for the same using enum.

Now, there are some constraints for a developer on the environment he works. Lets say if you are forced to work on Java 1.4, how do we implement this feature.

Lets create a new interface for Enums

Lets now implement our Loan enum here:

Phew! Its done.

No comments: