Two objects have the same references, surely the same?

enter image description here

My question is based on line 26. Here is my analysis:

Class A
  intstance variable: Class B;


If i use

A.equals(Class B)


Does line 26 really return true?

Because in C ++, a pointer will point to the same address under some circumstances.


source to share

1 answer

Does line 26 really return true?

No, it never returns true

unless you pass the exact same object reference to it.

The reason for this is that Java objects are not "embedded" within each other: there is a reference to B

inside A

, but it refers to a completely different object. Therefore, "false downgrade" is not possible: the place where the class reference is stored B

inside the class instance A

does not match the place where it is stored B




All Articles