Properties
implements Map<Object, Object>
- not Map<String, String>
.
You're trying to call this constructor:
public HashMap(Map<? extends K,? extends V> m)
... with K
and V
both as String
.
But Map<Object, Object>
isn't a Map<? extends String, ? extends String>
... it can contain non-string keys and values.
This would work:
Map<Object, Object> map = new HashMap<Object, Object>();
... but it wouldn't be as useful to you.
Fundamentally, Properties
should never have been made a subclass of HashTable
... that's the problem. Since v1, it's always been able to store non-String keys and values, despite that being against the intention. If composition had been used instead, the API could have only worked with string keys/values, and all would have been well.
You may want something like this:
Map<String, String> map = new HashMap<String, String>();
for (String key : properties.stringPropertyNames()) {
map.put(key, properties.getProperty(key));
}
Hashtable<Object, Object>
, even things which are not strings -- even keys which are not strings. – Spiffy