You can not. There is no clock mechanism in Java that is built into Java. Obviously, you could do a survey. But then it will not "live."
AspectJ may allow such a reflection, but I'm not sure if it is done for primitive variables, or only when you use getters and setters.
The pure Java way is to make the variable private and use getters and setters.
private valueToBeWatched; public void setValue(int newval) { valueToBeWatched = newval; notifyWatchers(); } public int getValue() { return valueToBeWatched; }
In a side note, avoid static whenever possible. In particular, public , but not final .
source share