lets say i have this variable :
...
Somekindofobject var = new Somekindofobject();
...
and i want to know where var is located on the heap ( by address , like 0x08 and so on),and to print the address out .
is it possible?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use
System.identityHashCodeto get a notion of sameness.It’s not perfect, but it’s pretty good.
If you do get the heap address of an object, remember that the JVM is allowed to move objects around (and frequently does when a generational garbage collector promotes a long lived object to an older generation) so the heap location of an object is not a good proxy for identity in all circumstances.