dagblog.
← Archive

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.

Medium version

Related articles

Related CZ Podcast episodes