Calling getters on an object vs. storing it as a local variable (memory footprint, performance)

后端 未结 6 462
庸人自扰
庸人自扰 2020-11-28 06:25

In the following piece of code we make a call listType.getDescription() twice:

for (ListType listType: this.listTypeManager.getSelectableListTyp         


        
6条回答
  •  天命终不由人
    2020-11-28 07:10

    I'm not sure either is preferred. What I would prefer is clearly readable code over performant code, especially when that performance gain is negligible. In this case I suspect there's next to no noticeable difference (especially given the JVM's optimisations and code-rewriting capabilities)

提交回复
热议问题