How to detect if a variable has changed?

前端 未结 6 1373
生来不讨喜
生来不讨喜 2020-12-10 06:16

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         


        
6条回答
  •  余生分开走
    2020-12-10 06:30

    you can also use flag concept, as when ever changing the value of x . assign true for an boolean variable. Keep boolean with default value as false. check by this way.

    This way is better than having getters and setters in base of performance, not to have reduntant code of two methods getters and setters.

提交回复
热议问题