If you ever needed convincing that Java generics are badly done…

… might I suggest Ken Arnold’s recent blog post on the subject. My favorite quote from the piece:

    Or, to show the same point in brief, consider this: Enum is actually a generic class defined as Enum<T extends Enum<T>>. You figure it out. We gave up trying to explain it. Our actual footnote on the subject says:

        Enum is actually a generic class defined as Enum<T extends Enum<T>>. This circular definition is probably the most confounding generic type definition you are likely to encounter. We’re assured by the type theorists that this is quite valid and significant, and that we should simply not think about it too much, for which we are grateful.

    And we are grateful. But if we (meaning David) can’t explain it so programmers can understand it, something is seriously wrong.

Now, I can’t be certain if he’s criticizing generic types in general (meaning he would be equally distressed at C++ templates–which admittedly are far more confusing than Java’s generic mechanism–or .NET’s generic types–which, while simpler than C++ templates, can still be somewhat confusing, as ex-DM and still-currently-friends buddy Joe Hummel points out), or the Java implementation of them, but either way, it stresses an important point: approach genericizing your code with care, regardless of your language, be it C++, Java, or .NET. The complexities can sneak up on you when you least expect it.