java.util.Properties 对象上的以下方法的调用:
put()putIfAbsent()putAll()get()
由于历史原因,java.util.Properties 继承自 java.util.Hashtable,但为防止污染 String 以外类型的属性值,不建议使用这些方法。
当映射中的键和值形参都为 String 类型时,不会报告对 java.util.Properties.putAll() 的调用。
此类调用是安全的,且没有更好的选择。
示例:
Object f(Properties props) {
props.put("hello", "world");
props.putIfAbsent("hello", "world");
props.putAll(new HashMap<>());
return props.get("Hello");
}
在应用快速修复后:
Object f(Properties props) {
props.setProperty("hello", "world");
props.putIfAbsent("hello", "world");
props.putAll(new HashMap<>());
return props.getProperty("hello");
}