I have an object in a Set that has it's guts updated by reference. Is there a way I can use the object hash ID (MyObject@93efa2ed
) or Eclipse ID (id=356
) to always watch in in my Expressions view even when it's out-of-scope?
I am using Eclipse Neon.
ur question is not quite clear to me, but i guess u mean this:
i dont know of any way (internal eclipse goody) that lets u ref' O by its eclipse debug ID or object hash.
but it can be done fairly simple: u just need to be able to reach O by some (lengthy) way of references from the current frame that is selected in the debugger to accomplish this.
the easiest way is to add some extra code to set O to some static var of some sort. U can even assign the static var while debugging manually, with the help of the "Display" view that lets u execute java code, that runs in the context of the current stack frame.
Steps:
MyWatcher.watches.put("a", o)
(replace 'o' by the expression that references O at ur breakpoint)MyWatcher.watches.get("a")
foo()
, b/c the map holds ar ref on O. public class MyCode {
public static void main(final String[] args) {
bar();
foo();
}
static void bar() {
final Set<Object> set = new HashSet<>();
for (int i = 0; i < 10; i++) {
final List<Integer> o = Arrays.asList(i);
set.add(o);
}
}
static void foo() {
System.out.println("bar");
}
}
public class MyWatcher {
public static final Map<String, Object> watches = new HashMap<>();
}