以HashMap源码中entrySet属性的实现为例
遍历HashMap有一种方法就是使用它enrySet()方法,但是HashMap源码中只有下面这段源码:非空时返回entrySet属性?什么时候给entrySet赋值的呢?很困惑。参考下面这篇博客,有了一定认识,记下来。
public Set<Map.Entry<K,V>> entrySet() {
Set<Map.Entry<K,V>> es;
return (es = entrySet) == null ? (entrySet = new EntrySet()) : es;
}