If you want to keep track of some variable or the result of a more complex expression, set up a watch for this variable or expression. This is useful when you need to evaluate something that is not regularly displayed on the list of variables, or to pin some instance variable thus eliminating the need to expand the tree after each step.
tip
When calling methods, make sure you are aware of their possible side effects (for example, changes to an outside variable), as they may alter the program flow or result.
inthasSideEffects(){// returns the number of entries in the list
someVariable++;return list.size();}
In the example, the value of someVariable will increment each time this code is evaluated, which may affect the behavior of the program.
Watches are evaluated in the context of the selected frame. Watches cannot be evaluated when they are out of context or when they fail to compile.
Add watch
After stopping at a breakpoint, click Add Watch in the Variables tab.
Enter the expression to be evaluated.
After you have added a variable/expression to Watches, it stays there and is evaluated for each step, providing you with the result in the current context.
Watches are a part of your project. This means you can stop and rerun the debugging session without risk of losing them.