• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Check if an int is (getting) bigger

 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to check when ever the int is gets bigger
i mean if there is two int's lets call them int1 and int2 , i want to see when ever int1 is getting bigger int2 will get bigger like int2++;

Let me put an example;



Thanks in Advance.
 
Rancher
Posts: 436
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you want to check at a specific point in your program flow if the value has changed? Then you need a variable to store the old value and need to compare that to the current. If it is different you act and you set the old value variable to the current value.

Or do you want to get notified whenever the value changes? That is not possible for primitive values in Java. You would need to create a class that capsules the value. The class should allow observers and throw events whenever the value changes (i.e. in setValue). The standard library has some support for this with java.util.Observable and java.beans.PropertyChangeSupport. The first is a general abstract definition, the latter allows an easy implementation.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to implement a wrapper class which notifies you about changes like that, design it with one method only (if possible) to change the value. The fewer places it can change, the less chance there is of your missing it.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic