Why java.util.Properties Isn't Safe
When java.util.Map came along to replace the older java.util.Hashtable, the java.util.Properties class already existed and inherited from Hashtable. At that point Hashtable didn't have the put and putAll methods introduced by the Map interface. When the Collections Framework was unified, however, the Map methods were also added to Hashtable. That brought put(Object key, Object value) and putAll(Map map) into Properties. So you can now put arbitrary objects into java.util.Properties, which is meant to represent a table of String keys and values. The Javadoc for java.util.Properties points out the problem too.
An aside. Of course, I don't read the Javadoc for classes everyone knows, which is on me. It took the book Effective Java: Programming Language Guide to bring this to my attention.
Related articles
Related CZ Podcast episodes
- #3 · Java 6 SE, Vývoj webových aplikací
Dagi and Filemon discuss Java 6 and web application frameworks. · Czech audio
- #1 · Vývojová prostředí v Javě
The first CZ Podcast episode looks at Java development environments. · Czech audio