Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

two objects have same reference are definitely 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 return true sometime?

Because in c++, the pointer will point the same address on some circumstances.

like image 202
AlexWei Avatar asked Apr 01 '26 13:04

AlexWei


1 Answers

Does line 26 return true sometime?

No, it never returns true unless you feed it the same exact object reference.

The reason for it is that Java objects are not "embedded" in one another: there is a reference to B inside A, but it refers to a completely different object. Hence, no "false aliasing" is possible: the place where the reference to class B inside an instance of class A is stored is not the same as the place where B itself is stored.

like image 106
Sergey Kalinichenko Avatar answered Apr 03 '26 03:04

Sergey Kalinichenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!