tubby
tubby

Reputation: 2144

continuously watch variables in eclipse even if it's not in scope

Say, I have a recursive code as below, where the variable 'resultshere' keeps getting updated in every recursive call. I would like to see the value of this variable from the "previous" call even for the brief period when it's not in current scope, and so does not have a value (yet).

How can I do this in eclipse?

Say my code is something like this:

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;
    }

}

Upvotes: 0

Views: 754

Answers (1)

Seelenvirtuose
Seelenvirtuose

Reputation: 20648

When debugging in Eclipse you always see the stacktrace. The stacktrace shows the methods that are called one after another. For recursive calls, you will see the same method being called:

Debug View - Stacktrace

Here you see three calls to the fun method. The third call is highlighted, and you see the parameter n being at value 3 (in the variables view).


If you are now interested in the previous calls, simply select the method call you wish:

Debug View - Previous Method

Here you see the first method call selected, and now you see all the variables (and parameters) - that this method call had - in the variables view.

Upvotes: 2

Related Questions