I don't know if the issue is caused by my version of the JDK, my version of IntelliJ or to by lack of Java complete understanding.
I was checking HashSet
implementation, and I wanted to know when the field keySet
is initialized. I saw the method
public Set<K> keySet() {
Set<K> ks = keySet;
if (ks == null) {
ks = new KeySet();
keySet = ks;
}
return ks;
}
which seems to be the place where the field is set the first time, but when I put my breakpoint on the condition, ks
is never null!
So I decided to check at what moment it is initialized but I don't seem to find it.
I simply ran the following instruction (1) step by step by using IntelliJ's Force Step Into button :
HashSet<String> set = new HashSet<>();
I get to the instruction (2) :
map = new HashMap<>();
And to the instruction (3)
this.loadFactor = DEFAULT_LOAD_FACTOR;
After the instruction (3), just before leaving the constructor public HashMap()
, if I evaluate the field keySet
, it is still null.
But right after that, exactly after instruction (2), before leaving the constructor public HashSet()
, if I evaluate map.keySet
it is not null anymore!
What kind of sorcery is this? Am I missing something here or is it an issue with my debugger? I am using jdk-9.0.1 and IntelliJ IDEA 2017.2.5