5.13. Assigning Values to Variables While Debugging
Problem
You want to change the values of variables while debugging to run tests on those new values.
Solution
Just double-click a field or variable name in the Variables view, and enter a new value in the dialog that opens.
Discussion
The Variables view displays the currently available variables and their values, as you can see at upper right in Figure 5-23.

Figure 5-23. Debugging with the Variables view
To change a variable’s value, just double-click it,
and enter a new value. For example, to change the value in
loopIndex from 3 to
2, double-click loopIndex in
the Variables view, enter 2 in the dialog that
opens (shown in Figure 5-24), and click OK.

Figure 5-24. Changing a variable on the fly
Note, however, that monkeying with data in a running program can break your code.
Eclipse 3.0
In Eclipse 3.0, some Java types, such as collections and maps, can be
displayed in a more compact and meaningful form using variable
filters. These filters are controlled with a
toggle button in the Variables view.
See Also
Recipe 5.12 on evaluating expressions.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access