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
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
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.
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.
I suppose you're refering to Objects toString() implementation.:
return getClass().getName() + "@" + Integer.toHexString(hashCode());
Maybe I'm wrong, but I don't think instances of a class are numbered. I have searched many times for a way to get instances of a particular class and according to my searches, it would be impossible. Instances have an address, but I see no use for a class instance number (objects are not sorted by class in memory AFAIK). Note that you can always create a mechanism for giving numbers to you instances of a particular class. Have a static count in the class and give its value to each new instance you create (in the constructor) and increment it each time. That would be a way to differentiate instances.