简体   繁体   English

链接方法调用Java性能

[英]Chaining method calls java performance

Okay so I want to know the performance cost of chaining method calls repeatedly. 好的,所以我想反复了解链接方法调用的性能成本。 For example if you are creating a game and you need to keep checking for collision detection, you would be calling methods the way I am thinking off. 例如,如果您正在创建游戏,并且需要继续检查碰撞检测,那么您将以我正在思考的方式调用方法。 Basically is it worth it to have methods like getters that you are going to repeatedly be calling? 基本上,拥有将要反复调用的类似getter的方法值得吗? For example in a large program having getters for private variables of every class and having to call them plus other methods... Would this reduce performance significantly? 例如,在一个大型程序中,每个程序都有用于每个类的私有变量的吸气剂,并且必须调用它们以及其他方法...这会大大降低性能吗? Thanks! 谢谢!

No, this will not cause significant overhead. 不,这不会导致大量开销。 For some things, it's supposedly faster to use a getter and setter if they only access a field. 对于某些事情,如果它们仅访问字段,则使用getter和setter的速度据说更快

Always use getters and setters :) 始终使用getter和setter :)

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

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