I am trying to make some sort of integer (be it int or Integer), x, that equals the sum of two other integers: a and b. a and b will change on occasion, so I want x to always be up-to-date.
Is there a way to do this without calling a getX()-like method that returns a + b?
Well, yes, but it’s no better than having a getter: the obvious alternative is to have setter methods for
aandbthat updatex.But I suspect that’s not what you wanted.
There’s no way to ‘link’ ints or Integers in Java without some kind of method call to update them.