Eclipse、调试、表达式值

Eclipse, debug, expression value

在使用eclipse 调试时,有什么方法可以检查特定表达式的值吗?表达式视图并不总是那么有用。

例如:

public class P 
{
    public boolean executed = false;

    public String getSomeString() {
        if (!executed) {
            executed = true; //set executed to true,so calling this method again will not yield the same result
            return "someStr";
        }else {
            throw new RuntimeException();
        }
    }
}

这里是主要方法:

public class Test {
    public static void main(String[] args) {
        P p = new P();
        p.getSomeString(); //breakpoint here, I want to check the value of this expression, but it is not assign to a variable.
        System.out.println();
    }
}

我在调试的时候想到了这个问题Struts2。

Dispatcher#serviceAction()的正文中,有一行proxy.execute();是来自DefaultActionInvocation#invoke()的字符串值,基本上是Actions返回的字符串。 但是 proxy.execute(); 的值没有分配给变量,也没有在 Dispatcher#serviceAction() 中的任何地方使用。那么如何从与视图关联的操作返回字符串?

只需在导航中标记表达式,然后按 Ctrl+Shift+I 或 "Run"/"Inspect"。 或者您可以使用 "Display" 视图。在这里你可以编写和存储你想要检查的表达式。

您可以将鼠标悬停在任何变量值上,或者在选择任何表达式后按 CTRL+SHIFT+I。

您可以在调试模式的观察表达式中添加变量。