Both person
and person2
are references, to the same object. But these are different references. So when you are running
person2 = null;
you are changing only reference person2
, leaving reference person
and the corresponding object unchanged.
I guess the best way to explain this is with a simplified illustration. Here is how the situation looked like before person2 = null
:
And here is the picture after the null assignment:
As you can see, on the second picture person2
references nothing (or null
, strictly speaking, since reference nothing and reference to null
are different conditions, see comment by Rune FS), while person
still references an existing object.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…