Reputation: 7565
When debugging in IDE, how does the IDE know how to calculate the watch value without changing the environment (writing to file, writing result to DB)?
Upvotes: 0
Views: 26
Reputation: 59302
Your observation cannot be generalized. An IDE typically makes changes during debugging, especially if a property has a side effect.
The following C# code:
using System;
namespace EvaluateChangesValue
{
class Program
{
static void Main()
{
var program = new Program();
Console.WriteLine(program.Value);
Console.ReadLine();
Console.WriteLine(program.Value);
Console.ReadLine();
}
private int member;
private int Value => member++;
}
}
Set a breakpoint at the first ReadLine()
, then add program.Value
to the watch window and see how the value gets increased due to the member++
statement.
In Java and Eclipse, it's a bit harder to make the same proof because for these reasons:
The code is similar to C#:
public class Program {
public static void main(String[] args)
{
Program p = new Program();
System.out.println(p.member);
System.console().readLine();
System.out.println(p.member);
System.console().readLine();
}
private int member;
public int getMember()
{
return member++;
}
}
And the screenshot:
Upvotes: 1