1

As the title states: I'd like to find an answer to the question why java.util.Properties extends Hashtable<Object, Object> instead of Hashtable<String, String>?

class Properties extends Hashtable<Object,Object> { ... }

I wonder because the method setProperty(String key, String value) accepts only String values and the properties are based on the String key-value representation. The full method body is on the link above and here:

public synchronized Object setProperty(String key, String value) {
    return put(key, value);
}

The same goes for the getProperty(String key) method and the other ones.

Is there any specific reason extend Hashtable<Object, Object> and use Strings? Is there any use-case I should be aware while using Hastable<Object, Object> or HashMap<Object, Object> like in this way?

Zoe
  • 27,060
  • 21
  • 118
  • 148
Nikolas Charalambidis
  • 40,893
  • 16
  • 117
  • 183

1 Answers1

1

Here’s one reason: The class predates generics.

Since: JDK1.0

The team updating the Java libraries for generics had to balance “now we can accurately capture semantics” and “people will have a lot a broken code”. Most of the time, the libraries were updated to compile and run with existing code, at some cost in specificity.

Bob Jacobsen
  • 1,150
  • 6
  • 9