After reading Matt Quail’s blog entry on how horribly hard JDK1.5 will be, I downloaded the early access compiler and started hacking on it.
I played around with a few little programs, then got stuck into PragDave’s Kata 6—read a dictionary of words, find all the anagrams, and print them out.
Here is my code. It gives generics and the JSR-201 enhanced for loop a good work out. The other features—enums, autoboxing, meta-data and static imports—aren’t used.
Observations:
Digression on Variance
Java JSR-014 generics suffer from a problem. Joshua Bloch (quoted by Michael Coté) gives a good nutshell explanation:
An
Integeris aNumber, but aListofIntegersis not aListofNumbers.
A solution to this problem is the experimental “variance” extension to generics, which ships with the early access compiler. These look really cool: there is little difference to users of the generic classes (except that more things ‘just work’1), and they aren’t that much harder for writers of generic classes.
Frankly, programmers2 will need to be discouraged from writing generic classes. They can be difficult to implement in a correct and maintainable fashion. The newly genericised java.util collections classes should be all the generics most of us need, most of the time.
Overall, I have to disagree with Matt. JDK 1.5 is a step forward. “The Masses” (as Matt refers to them) will find their day-to-day coding simplified3. “The Smart People” will need to learn a slightly bigger language—hardly a problem for them.
1 Or, to put it another way, fewer things fail mysteriously.
2 Especially the smart ones that assume that everybody else is as smart as them.
3 And day-to-day simplicity is good, especially in the face of things like this, this or this.
Comments
The early access compiler, while seeming a bit buggy (try out iterating over a LinkedList with some generic type using the enhance for loop), definitely eases coding and makes it more readable.
I look forward to a more stable release.