Variable checker? Java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Variable checker? Java

Is it possible to check if a variable has changed, so that Methode use then new variable? (But I don't mean a timer. I mean something that only run when the variable change.) Java Thanks

5th Aug 2018, 7:22 PM
Stayex
Stayex - avatar
6 Answers
0
A TimerTask would be my first idea, it only has to fire every second
6th Aug 2018, 7:34 PM
Jonas Schröter
Jonas Schröter - avatar
+ 1
You could restrict the acces to the variable making it private. Then you create a setter. Now the variable has to be changed through the setter and you know when it's updated.
5th Aug 2018, 7:33 PM
Jonas Schröter
Jonas Schröter - avatar
+ 1
Like you wanna check if the time changed?
5th Aug 2018, 7:49 PM
Jonas Schröter
Jonas Schröter - avatar
0
But (how) can I use this for something like a clock? So that it auto refresh the methode of the clock. Thanks for the answer.
5th Aug 2018, 7:46 PM
Stayex
Stayex - avatar
0
Yes.
5th Aug 2018, 7:51 PM
Stayex
Stayex - avatar
0
So, that the the clock print out every time when a second is over. Or is a timer the only way?
5th Aug 2018, 8:22 PM
Stayex
Stayex - avatar