How not to name a product

11 AM July 10, 2006

If I were building a system for capturing training records, I wouldn’t call it, “Train Rec”, would I?

By alang | # | Comments (2)
(Posted to Rants, Software Development and javablogs)

java.util.Properties and Generics

12 AM July 10, 2006

I can’t wait for Java 6.0. It looks like community involvement is a success.

For instance, just now, I was working in JDK1.5, where I had a properties file and needed to see the kes. I wrote:

  for (String key : props.keySet()) { 

Which seems sensible enough, except that the compiler rejects it with, “Type mismatch: cannot convert from element type Object to String”. A little bit of digging found the JDK1.5 Properties class declaration:

   class Properties extends Hashtable<Object,Object> {

Given that the Javadoc says, “Each key and its corresponding value in the property list is a string”, I can’t see why Properties doesn’t extend Hashtable<String, String>. Looks like laziness to me, but if someone has an alternate explanation, I’d appreciate hearing it.

On the bright side, it seems that I’m not the first person to encounter the issue, and, according to this bug report, Java 6.0 will have a way to do what I want without casting. Hoorah!

Update: This is the pre-Java 6.0 workaround:

  for (String key : (Set<String>) (Set) props.keySet()) {

Oh, and don’t forget to add @SuppressWarnings(“unchecked”) to the method declaration.

By alang | # | Comments (2)
(Posted to javablogs, Java and Rants)
© 2003-2006 Alan Green