Alignment: Chaotic Java

Monday, December 19, 2005

Class Enum<E extends Enum<E>>

Check it out. It's not the first time I've seen this, but I've found myself explaining it more than once lately, so I thought I'd share my insights with the blogsphere.

I'm probably not the first and not the last who was baffled by this line. Probably, the thought "What the hell were Sun thinking when they wrote this" came across many, many minds and in many different languages.

At first glance, this looks like the recursive generic definition from hell. However, when examined closely, this defintion makes perfect sense. In fact it could be summed as "Extenders of this class (or interface) can only pass themselves (or extenders/implementors) as E".

Literally, it means "If a class extends this class, it should pass a parameter E. The parameter E's bounds are for a class which extends this class with the same parameter E". Replace E with MyClass for a minute there, and let's look at it again: If MyClass extends Enum, it should pass a parameter E. The parameter E's bounds are for a class which extends Enum<E>, which is MyClass!

With this note of self-created confusion, I'd like to thank you, the readers, for making this blog pass the 1,000 hits in just a little over a month. I have a lot to thank to java.blogs for being a great jump-start aggregator, but nothing can be compared to the feeling I get when I see the counter showing me a user getting in not through java.blogs. So, thanks again!

Interesting Topics
Time to make a difference with your Java
Possible advantages of X2J - Primary Keys

0 Comments:

Post a Comment

<< Home