Posts

Showing posts from July, 2008

The Enum is perfect... well almost.

Ok so its time to admit to something. I'm deeply in love with Java's Enum! In my opinion it was the best part of Java 5 and I still wonder why it took Sun 10 years to add this powerful static modeling construct. The power of the Enum Although there certainly are known limitations of the Enum, i.e. how you can't extend it , I have never run into a practical limitation myself. Until now that is. The issue I want to raise is that of Enum forward referencing . The great Alan Turing taught us that at the end of the day, everything can be modeled by a Turing Machine and finite automata. We may not often consciously operate at this level, but many things still makes sense to model this way being it a regular expression matcher, navigation rules or similar. The Java Enum appears to be a perfectly simple, fast and type-safe way of modeling this... or does it? State machine with an Enum Since the Java Enum effectively is just a group of static class instances, it allows us to attach