• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

why Properties extends Hashtable with Object parameter type instead of String?

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone know why definition of java.util.Properties extends Hashtable<Object, Object> instead of Hashtable<String, String>? As stated by javadoc, Properties can and should only hold String right?

Also, is there better way to process a Properties entries without cast?


Thanks,
Z
 
author & internet detective
Posts: 39341
755
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Zemian,
If the subclass used different parameter types, it wouldn't override the method. This goes back to the pre Java 5 days. When generics were introduced, they tried to keep backward compatibility with existing code that was using the Object API.
 
Sheriff
Posts: 21758
102
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To be honest, I agree with Zemian. The only reason why old code would break if it were a Hashtable<String,String> would be if programmers put Objects directly into the Properties object using the put method. IMHO, that would mean using a Properties object in a way it wasn't meant to be used.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, but the thing it, it is possible that people used put(Object, Object). Illogical as that may be, it's perfectly legal. It would have been better if Properties did not extend Hashtable in the first place - it should have contained one instead. But it's one of those bad design decisions that Sun made long ago, and now we're stuck with it. And Sun does take their backward compatibility very seriously, even here.
 
Zemian Deng
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right, backward compatibility. I was going to guess that. Well, I am glad some of you agree what I found. It just bugs me that with new Generic added, I still can't loop a Properties without casting.

Thanks for sharing your thoughts.
Cheers,
Z
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!