public static void main(String[] args) {
IdentityHashMap<Integer, Object> m1 = new IdentityHashMap<Integer, Object>();
Integer ONE = 1;
Integer TWO = 2;
Integer OTHER_ONE = new Integer(1);
Integer OTHER_TWO = new Integer(2);
m1.put(ONE, new Object());
m1.put(TWO, new Object());
System.out.println(m1.keySet()); // [1, 2]
m1.remove(OTHER_ONE); // Does not remove
System.out.println(m1.keySet()); // [1, 2]
m1.remove(ONE); // Does remove
System.out.println(m1.keySet()); // [2]
m1.keySet().removeAll(Arrays.asList(OTHER_TWO)); // ...
System.out.println(m1.keySet()); // [] WHAT?
}
我在源代码中找到了答案(见下文),但我不知道最终原因。它是一个错误吗?