0

During an Eclipse debugger session in the eclipse debugging view, it is possible to change arbitrary primitive variables and even Strings.

I wonder why it does not seem possible to change variable references to objects as well. E.g. if there is something like

 ClassLoader cl = ClassLoader.getCallerClassLoader()

in the code I'd like to be able to bind the variable ("change its value" in a relaxed sense) to

 cl = Thread.currentThread().contextClassLoader

during debugging.

Am I wrong (it is possible to do this) and if not, are there any conceptional reasons (so other reasons than "nobody simply has done this yet")?

4

2 回答 2

4

It transpires that you can actually do this in a round about way. Code:-

import org.junit.Test;

public class TestDebug {

  @Test
  public void test() {
    Object foo = new Object();
    System.err.println(foo);
  }
}

Breakpoint on the syserr line.

Select 'this' in the variables view then type into the details area at the bottom the following code:-

foo = new java.util.ArrayList()

Now select the above expression and hit shift+ctrl+i (inspect) and it will execute the code. Lo and behold foo now contains an array list!

于 2012-10-11T14:00:19.070 回答
2

You can manually execute any piece of Java code in a suspended thread in the debugger, including assignments to all variables or fields which are visible in the context of the current stack frame.

So yes, that assignment should be possible.

于 2012-10-11T20:03:35.870 回答