AbstractSet抽象类源码解析
2016-07-16 15:53
295 查看
继承AbstractCollection
实现Set
源码如下
实现Set
源码如下
package java.util; public abstract class AbstractSet<E> extends AbstractCollection<E> implements Set<E> { protected AbstractSet() { } 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; } } public int hashCode() { int h = 0; Iterator<E> i = iterator(); while (i.hasNext()) { E obj = i.next(); if (obj != null) h += obj.hashCode(); } return h; } public boolean removeAll(Collection<?> c) { boolean modified = false; if (size() > c.size()) { for (Iterator<?> i = c.iterator(); i.hasNext(); ) modified |= remove(i.next()); } else { for (Iterator<?> i = iterator(); i.hasNext(); ) { if (c.contains(i.next())) { i.remove(); modified = true; } } } return modified; } }
相关文章推荐
- 找出字符串
- Python print输出不换行
- Android M 新的运行时权限开发者需要知道的一切
- volatile关键字
- 文本挖掘,我们想要得到什么
- lnmp一键安装包
- poj 3126 (BFS + 素数打表)
- NOIP提高组2011 观光公车
- HDU 5253 最小生成树 kruscal
- Java多线程经典案例-生产者消费者
- BZOJ 4568 [Scoi2016]幸运数字 【倍增线性基
- 圆周舞蹈 (Standard IO)
- Span【推荐】
- 互斥锁和条件变量
- Set接口源码解析
- html页面通过特殊链接:打电话,发短信,发邮件详细教程
- cas 在 反向代理环境中的https 配置
- SCU2016-06 R题矩阵快速幂优化的dp
- JS+CSS3实现超炫的散列画廊特效
- 定时器