//先判断类型是否一致,之后判断大小是否相等,最后调用方法containAll
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof Set))
return false;
Collection<?> c = (Collection<?>) o;
if (c.size() != size())
return false;
try {
return containsAll(c);
} catch (ClassCastException unused) {
return false;
} catch (NullPointerException unused) {
return false;
}
}
HashSet源码解析
于 2022-07-28 22:05:56 首次发布