Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get instance number

Tags:

java

Is there way how to get instance number or id, I mean that what you can see in eclipse Debug>Variables window after class name in value column.

Thanks

like image 860
liborw Avatar asked Nov 03 '25 03:11

liborw


2 Answers

See System.identityHashCode which returns the number that would be returned if Object.hashCode had not been overridden on an object. It is not a perfect proxy for identity since multiple objects might have the same identity hash code, but it is pretty useful for debugging.

like image 154
Mike Samuel Avatar answered Nov 04 '25 19:11

Mike Samuel


By default, debugger shows you the result of toString() method with the hashCode of the object. So, you can see the value by executing hashCode() method.

like image 33
Vladimir Ivanov Avatar answered Nov 04 '25 19:11

Vladimir Ivanov



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!