这是有问题的代码,为此示例简化:
/** A version of Hashtable that lets you do
* table.put("dog", "canine");, and then have
* table.get("dogs") return "canine". **/
public class HashtableWithPlurals extends Hashtable {
/** Make the table map both key and key + "s" to value. **/
public Object put(Object key, Object value) {
super.put(key + "s", value);
return super.put(key, value);
}
}
Run Code Online (Sandbox Code Playgroud) Properties defaults = new Properties();
defaults.put("color", "black");
Properties props = new Properties(defaults);
// This prints "null, black"
System.out.println(props.get("color") + ", " + props.getProperty(color));
Run Code Online (Sandbox Code Playgroud) java ×2