Hacking on JDK 1.5 Early Access

10 PM June 16, 2003

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:

  • Enhanced for loop is useful. It does away with the boiler plate for getting, testing and next()ing iterators.
  • The generics enhancements are way cool. My program contains no casts, despite manipulating a Dictionary of Lists of Strings and a List of Lists of Strings

Digression on Variance

Java JSR-014 generics suffer from a problem. Joshua Bloch (quoted by Michael Coté) gives a good nutshell explanation:

An Integer is a Number, but a List of Integers is not a List of Numbers.

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.

By alang | # | Comments (1)
(Posted to Software Development)

Comments

At 13:22, 12 Nov 2003 Scott Arbeitman wrote:

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.

(#)

Add Comment




(Not displayed)






(Leave blank line between paragraphs. URLs converted to links. HTML stripped. Indented source code will be formatted with <pre> tags.)




© 2003-2006 Alan Green