public class ShortSet {
public static void main(String[] args) {
Set<Short> s = new HashSet<Short>();
for(short i = 0; i < 100 ;i++) {
s.add(i);
s.remove(i-1);
}
System.out.println(s.size());
}
}
输出结果为100
s.add(i) short会自动装箱为Short类型
s.remove(i-1) short-integer=integer 所以s.remove(i-1)会返回false
源码位置 HashMap-->removeNode方法
if (p.hash == hash &&
((k = p.key) == key || (key != null && key.equals(k))))