は違いを示す例です:最初のケースで
import java.util.*;
public class Test {
public static void main(String[] args) {
Properties defaults = new Properties();
defaults.setProperty("x", "x-default");
Properties withDefaults = new Properties(defaults);
withDefaults.setProperty("x", "x-new");
withDefaults.remove("x");
// Prints x-default
System.out.println(withDefaults.getProperty("x"));
Properties withCopy = new Properties();
withCopy.putAll(defaults);
withCopy.setProperty("x", "x-new");
withCopy.remove("x");
// Prints null
System.out.println(withCopy.getProperty("x"));
}
}
を、私たちは「X」プロパティの新しいデフォルト以外の値を追加し、それを削除しています。私たちが "x"を求めるとき、実装はそれが存在しないことを発見し、代わりにデフォルトを調べます。
2番目のケースでは、がデフォルトのであることを知らずに、デフォルト値をプロパティにコピーしています。これらはプロパティの値です。次に、「x」の値を置き換えて、それを削除します。 "x"を求めるとき、実装はそれが存在しないことに気付くでしょうが、それを調べるデフォルトがないので、戻り値はnullです。
「固定」コードのスニペットはどれですか? – home
第2のもの。リンクを追加しました。 –