I am debugging a java application using eclipse debugger.
I wonder about the object ids the debugger shows to me (see also Java object ID in jvm ).
Is it possible to make these ids identical between two debugging session? So that, when i debug the same application twice (one after the other) same objects have the same id? Or is it possible to set breakpoints like this: Break at whatever statement when object with given id is involved?
I have in mind a definition of breakpoint that does not involve a certain line of code. I have in mind a breakpoint that is indepent from line of code. A breakpoint that only involves id. The debugger, having a tool like these ids at hand: can he not use it to offer me a feature like i propose?
This is not possible. The id is internal to the debugger and randomly generated each time an object is created (or restored from serialization etc.). Furthermore you shouldn’t try to abuse the property that way.
Luckily Java has something which will likely suit your needs:
Object#hashCode. It is a (semi-)unique identifier for each unique object (as far asObject#equalsis concerned). It can thus be used to identify a object consistently across debugging session as long as the data is the same.Eclipse can generate a
hashCode()for you based on all class member variables. I’d suggest using that since it will likely suit your needs and guarantees that the hash has all desired properties. It is under Right click->Source->Generate hashCode() and equals()As far as the breakpoint is concerned, just create an if checking for the correct object and place a breakpoint inside.