Friday, May 2, 2008

Java v.s. C#: enum

Here is one thing that's done better in Java than C#: enum

The enum types in Java 1.5 is far more flexible than its C# counterpart. Instead of defining it as a "value type", or primitive that has limited room for extensibility, it's defined as a normal class with a list of static final memebers. You can choose to define your own constructor, memeber fields and methods.

Both C# and Java provide many basic utility functions for enums, such as converting back and forth between enum type and strings, etc.

Here is an excellent article on the implementation of enum in Java.