持续观察 eclipse 中的变量,即使它不在范围内
continuously watch variables in eclipse even if it's not in scope
说,我有一个如下的递归代码,其中变量 'resultshere' 在每次递归调用中不断更新。我想从 "previous" 调用中查看此变量的值,即使是在它不在当前范围内的短暂时间内,因此(还)没有值。
如何在 eclipse 中执行此操作?
假设我的代码是这样的:
public class Test {
public static void main(String[] args) {
System.out.println(fun(5));
}
static int fun(int n) {
int resultshere = 0;
int ret = 0;
if (n == 0) {
resultshere = 1;
return resultshere;
}
ret = fun(n - 1);
resultshere = n * ret;
return resultshere;
}
}
在 Eclipse 中调试时,您总是会看到堆栈跟踪。堆栈跟踪显示了一个接一个被调用的方法。对于递归调用,您将看到调用相同的方法:
在这里您可以看到对 fun
方法的三个调用。第三个调用突出显示,您会看到参数 n
的值为 3
(在变量视图中)。
如果您现在对以前的调用感兴趣,只需 select 您希望的方法调用:
在这里您可以看到第一个方法调用 selected,现在您可以在变量视图中看到该方法调用具有的所有变量(和参数)。
说,我有一个如下的递归代码,其中变量 'resultshere' 在每次递归调用中不断更新。我想从 "previous" 调用中查看此变量的值,即使是在它不在当前范围内的短暂时间内,因此(还)没有值。
如何在 eclipse 中执行此操作?
假设我的代码是这样的:
public class Test {
public static void main(String[] args) {
System.out.println(fun(5));
}
static int fun(int n) {
int resultshere = 0;
int ret = 0;
if (n == 0) {
resultshere = 1;
return resultshere;
}
ret = fun(n - 1);
resultshere = n * ret;
return resultshere;
}
}
在 Eclipse 中调试时,您总是会看到堆栈跟踪。堆栈跟踪显示了一个接一个被调用的方法。对于递归调用,您将看到调用相同的方法:
在这里您可以看到对 fun
方法的三个调用。第三个调用突出显示,您会看到参数 n
的值为 3
(在变量视图中)。
如果您现在对以前的调用感兴趣,只需 select 您希望的方法调用:
在这里您可以看到第一个方法调用 selected,现在您可以在变量视图中看到该方法调用具有的所有变量(和参数)。