A
ankur
Sorry for this irrelevant question , but if I cannot resist asking:
In the class HashMap.java how is the
private transient Set<Map.Entry<K,V>> entrySet = null;
gettting initialized with all the map entries ?
I could not figure this out by looking at this segment of code that
also contains the constructor:
public Set<Map.Entry<K,V>> entrySet() {
return entrySet0();
}
private Set<Map.Entry<K,V>> entrySet0() {
Set<Map.Entry<K,V>> es = entrySet;
return es != null ? es : (entrySet = new EntrySet());
}
public final class EntrySet extends AbstractSet<Map.Entry<K,V>> {
public Iterator<Map.Entry<K,V>> iterator() {
return newEntryIterator();
}
public boolean contains(Object o) {
if (!(o instanceof Map.Entry))
return false;
Map.Entry<K,V> e = (Map.Entry<K,V>) o;
Entry<K,V> candidate = getEntry(e.getKey());
return candidate != null && candidate.equals(e);
}
public boolean remove(Object o) {
return removeMapping(o) != null;
}
public int size() {
return size;
}
public void clear() {
HashMap1.this.clear();
}
}
How is the statement entrySet = new EntrySet() causing the
initialization ? Constructor does not seem to do anything about the
initialization ?
Thanks,
Ankur
In the class HashMap.java how is the
private transient Set<Map.Entry<K,V>> entrySet = null;
gettting initialized with all the map entries ?
I could not figure this out by looking at this segment of code that
also contains the constructor:
public Set<Map.Entry<K,V>> entrySet() {
return entrySet0();
}
private Set<Map.Entry<K,V>> entrySet0() {
Set<Map.Entry<K,V>> es = entrySet;
return es != null ? es : (entrySet = new EntrySet());
}
public final class EntrySet extends AbstractSet<Map.Entry<K,V>> {
public Iterator<Map.Entry<K,V>> iterator() {
return newEntryIterator();
}
public boolean contains(Object o) {
if (!(o instanceof Map.Entry))
return false;
Map.Entry<K,V> e = (Map.Entry<K,V>) o;
Entry<K,V> candidate = getEntry(e.getKey());
return candidate != null && candidate.equals(e);
}
public boolean remove(Object o) {
return removeMapping(o) != null;
}
public int size() {
return size;
}
public void clear() {
HashMap1.this.clear();
}
}
How is the statement entrySet = new EntrySet() causing the
initialization ? Constructor does not seem to do anything about the
initialization ?
Thanks,
Ankur