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!
Liked Chaotic Java? It's free! But I also make some other things that aren't, which you might like. Like Firewall, a rule changing, turn based strategy game for iOS.
February 24th, 2006 at 8:24 am
[...] When you write a new enum, you are actually creating a class containing static instances of itself – The enum values. The class will extend the class Enum (discussed earlier for its weird generification), and every instance will be initialised with a String – the name of the enum value – and an integer – the enum’s ordinal value. So, for example, the following enum: [...]
March 7th, 2006 at 11:01 pm
[...] When you write a new enum, you are actually creating a class containing static instances of itself – The enum values. The class will extend the class Enum (discussed earlier for its weird generification), and every instance will be initialised with a String – the name of the enum value – and an integer – the enum’s ordinal value. So, for example, the following enum: [...]
July 31st, 2006 at 10:35 am
[...] A type parameter was added to Table. However, that type is needed in Column as well to describe the Table containing it, so it was added to Column too. The idea of the weird circular typing is explained in another post of mine. [...]