Have you taken the leap into the new Java 5 syntax yet? If not there are a number of blogs showing up that are offer great information on the new features. Take Rajneesh on Autoboxing and Tim Pokorny on Generics. Rajneesh’s blog entry is a short but effective explanation as to what Autoboxing is all about.
Autoboxing is the term for treating a primitive type as an object type. The compiler automatically supplies the extra code needed to perform the type conversion.
The blog is supported with a couple of nice examples. Integer i = new Integer(9); Integer j = new Integer(13); Integer k = i + j; // error prior to JDK 1.5 The pro’s and con’s according to Rajneesh; the code maybe more uncluttered but with unexpected performance and behavior at times and the infamous NullPointerException because of the null and zero reverse mapping problem. Tim’s blog is more of an inspirational than practical guide. However the entry is full of great links to talks and tutorials (including a 2004 JavaPolis presentation by Neal Gafter ). The best message that Tim provides is his story of how he started with Generics.
I was hesitant to accept them at first. However, with more and more use they have grown on me to the point that they are a central part of the way I use Java. While most people are comfortable with the simple use cases (such as assigning a type to a collection), the more advanced concepts seem to surround themselves with an aura of mystery.
To be sure there are some interesting use cases for Generics beyond the assigning of a type to a collection. However they do look like “voodoo art? at first glance. It just takes time to get used to reading the new syntax and finding insightful blogs such as these two do help. Tim’s point is well taken; we do need to invest time in figuring out what the new language features are all about.