简体   繁体   English

Java:如何在没有方法调用的情况下实现指针效果?

[英]Java: How do I achieve a pointer effect without method calls?

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 . 我试图做一些整数(是intInteger ), x ,等于两个其他整数的总和: ab a and b will change on occasion, so I want x to always be up-to-date. ab有时会改变,所以我希望x始终是最新的。

Is there a way to do this without calling a getX() -like method that returns a + b ? 有没有办法做,而无需调用getX()式的方法,它返回a + b

Well, yes, but it's no better than having a getter: the obvious alternative is to have setter methods for a and b that update x . 嗯,是的,但它并不比拥有一个getter更好:显而易见的替代方案是为ab更新x setter方法。

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. 如果没有某种方法调用来更新它们,就无法在Java中“链接”整数或整数。

不,没有办法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM