I'm a beginner to Java coming from C++ background.
The way that I can have addresses in C++ and see if the pointer are really pointing to the same object, I want to see the same in Java e.g. I have
String s1 = "abc"; String s2 = "abc";
I know that s1 and s2 are pointing to the same object in memory but how can I see this happening. I read something about hashCode() but still not very clear about that + if I do the same for Integer,
Integer i1 = new Integer(1); Integer i2 = new Integer(1);
then even though i1 and i2 are pointing to different object, hashCode() would return the same value, so what is the way to see whether reference are poiting to the same object or not.
That will return true. Just like C/C++ == means identical. equals (depending on implementation of course) is supposed to mean the same value.
> > Integer i1 = new Integer(1); > Integer i2 = new Integer(1); > > then even though i1 and i2 are pointing to different > object, hashCode() would return the same value, so what is > the way to see whether reference are poiting to the same > object or not. > > Any Help would be really helpful.. > > TIA, > Timsy.