Enums in Java (One More Time)
Subject:   Want enums added to Java? Your wish is granted!
Date:   2003-05-08 08:06:48
From:   jimoore
Response to: Want enums added to Java? Your wish is granted!

Thanks for you compliments, and I share your enthusiasm for Google. I am still amazed at how quickly Google was able to displace all other search engines to become everyone's favorite.

Let me make a few comments about JSR 201. I started work on this article and the jEnum translator before JSR 201 came into existence. Thanks to John Zukowski, I became aware of JSR 201 as I was near completion of the article. At one point I modified the jEnum translator so that the Java file it created looked reasonably close to the one described in JSR 201, but I changed things back since I liked my original design much better. While I support the idea of adding enums to Java, in general I do not support major language changes, and it looks like Java 1.5 will contain many changes. I am fully against most of them, especially generics.

<rant against="generics>
For Java, I believe that the addition of generics does not solve a problem. The concept of generics is a siren's song that needlessly complicates the syntax and semantics of the language and its library without adding much value. I understand that it moves some run-time checks into compile-time checks, and in general that is a good thing, but the benefits in this particular case do not make up for the drawbacks. Several topics in the "Generics" forum of the Java Developer Connection highlight issues and user frustrations with their addition.

In my professional career, I have moved from Ada to C++ to Java (ignoring other languages before Ada), and I found the simplicity and elegance of Java to be a welcome relief. Learning and teaching the Java language is straightforward. Additional work is required to master the extensive library and related technologies (JDBC, servlets, etc.), but that is exactly where the effort belongs. No other language has such comprehensive support in a standardized way.

Now back to enums. Using enums as described in JSR 201 is relatively straightforward, but they are constructed by the compiler using generics. Current implementation decisions relative to the addition of generics imply that one will need a JRE version 1.5 runtime in order to run code with generics. (Note that this was not the original understanding of many of those who voted in favor of their addition.) These decisions are subject to change before 1.5 is released, but if they are not changed, this means that you can't use code with generics with any project unless it is fully upgraded to version 1.5, and you can't use them as part of an applet for many years, until most of your Internet users have upgraded to 1.5 or later. The Java code produced by the jEnum translator should be compatible with version 1.2 and all subsequent versions, so it is safe to use it for most current Java projects. And, of course, the jEnum translator is available now, so you don't have to wait for the release of 1.5.