The Artima Developer Community
Sponsored Link

Java Answers Forum
How to get obj address / actual reference value?

1 reply on 1 page. Most recent reply: Mar 20, 2003 4:00 PM by Rich Burgis

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Timsy

Posts: 3
Nickname: timsy
Registered: Mar, 2003

How to get obj address / actual reference value? Posted: Mar 20, 2003 3:07 AM
Reply to this message Reply
Advertisement
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.

Any Help would be really helpful..

TIA,
Timsy.


Rich Burgis

Posts: 17
Nickname: songbird
Registered: Mar, 2003

Re: How to get obj address / actual reference value? Posted: Mar 20, 2003 4:00 PM
Reply to this message Reply
use i1.equals( i2 )

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.

Flat View: This topic has 1 reply on 1 page
Topic: Cross Context calls in Tomcat?? Previous Topic   Next Topic Topic: Java Question

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use