I have found myself wanting to do certain things in my programs only if a variable has changed. I have so far been doing something like this:
int x = 1;
in
Since you want to find and perform some action only if the value changes, I would go with setXXX, for example:
public class X
{
private int x = 1;
//some other code here
public void setX(int proposedValueForX)
{
if(proposedValueForX != x)
{
doOneTimeTaskIfVariableHasChanged();
x = proposedValueForX;
}
}
}