+ 2

How to find adress of a object in java or its reference in memory can it be done???

Creating a object obviously by using new it will go to heap but it is been referenced from main function loaded in stack using the object name and hence how will we find the address of referenced object

28th Feb 2018, 7:39 PM
ashish jain
ashish jain - avatar
4 odpowiedzi
+ 2
you can find the address of reference by using sun.misc.Unsafe class but it is very unsafe
28th Feb 2018, 8:03 PM
Vijay Dangi
Vijay Dangi - avatar
+ 2
well Java wanted to make sure that accessing an address in memory is hard . as Vijay said you need an object of Unsafe class ....... looks like it's constructor is private ...... so good luck instantiating it. (I'm not saying it's impossible thou .... I just couldn't get it done) if you Google it you'll find something for sure
28th Feb 2018, 8:11 PM
Farshaad Heydari
Farshaad Heydari - avatar
+ 1
does hashcode returns the exact memory address or it is having its own JVM related concept
28th Feb 2018, 8:13 PM
ashish jain
ashish jain - avatar
0
I'm not sure but I don't think so since hashcode changes for every execution
28th Feb 2018, 8:20 PM
Farshaad Heydari
Farshaad Heydari - avatar