Suppose I have a class
public class Foo
{
public void doThing() { ...}
}
Say I have a lot instances of Foo
, but I'm only particularly interested in one of them.
How would I "tag" that instance and set a "conditional breakpoint" in doThings
that would stop ONLY for the tagged instance?
Is there a "builtint" way, particularly by the Eclipse debugger, to do this?
Currently, I have to manually create a boolean flag in the Foo
class setting it to false by default, and create a conditional breakpoint based on that in doThings
.
Then when I encounter the interested object, I would set the flag to true
by executing the setter code in the Display
window.
But clearly, that requires modifying the code and adding some boilerplate, which is not always possible or a good thing to do.
I don't know of any "proper" way, but one approach would be to call hashCode()
in the watch window when you first create it, and then make the breakpoint conditional on the hashCode()
as well. So you'd need to change the break point each time you ran it - somewhat annoying, but it does at least give you a constant value that you can use to refer to the object. (That's assuming the class doesn't override hashCode()
, of course - if you've got many instances with the same hash code, that makes things trickier.)
See more on this question at Stackoverflow