This is keySet()
method on HashMap
class from JDK. Why did the author assign the field keySet
to local variable ks
?
public Set<K> keySet() {
Set<K> ks;
return (ks = keySet) == null ? (keySet = new KeySet()) : ks;
}
What is the difference between the above and the below? Does this have something to do with thread-safety?
public Set<K> keySet() {
return (keySet == null ? (keySet = new KeySet()) : keySet;
}
See Question&Answers more detail:os