在 Android 文档中有一个 article关于建议避免使用内部 getter/setter 的“性能提示”。 最近publication在MOBILESoft 2016 session 同意这一建议。
然而,根据lint documentation :
As of Android 2.3 (Gingerbread), this optimization is performed automatically by Dalvik, so there is no need to change your code; this is only relevant if you are targeting older versions of Android.
是否有关于此的任何官方和更新信息?
最佳答案
我无法就该出版物发表意见,但我认为 this可以支持 lint 文档所说的内容。
我自己的准则是更喜欢干净的代码/结构(在这种情况下,如果你不使用 getter/setter,你可能会在你的类中散布代码重复,并且很难进行更改,因为你需要在某些地方进行更改) 而不是微观性能改进。
关于java - Android 内部的 getter/setter 真的有代码味道吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38376880/