I am reading the JDK source code. I see a method public Collection<V> values()
in class HashMap
:
public Collection<V> values() {
Collection<V> vs = values;
if (vs == null) {
vs = new Values();
values = vs;
}
return vs;
}
But I think this logic will be shorter and more concise:
public Collection<V> values() {
if (values == null) {
values = new Values();
}
return values;
}
I think there must be a reason behind this. Please tell me why.