Java Method invocation vs using a variable

前端 未结 14 2412
北海茫月
北海茫月 2020-11-27 02:57

Recently I got into a discussion with my Team lead about using temp variables vs calling getter methods. I was of the opinion for a long time that, if I know that I was goin

14条回答
  •  自闭症患者
    2020-11-27 03:13

    The virtual machine can handle the first four local variables more efficiently than any local variable declared after that (see lload and lload_ instructions). So caching the result of the (inlined) getter may actually hurt your performance.

    Of course on their own either performance influence is almost negligible so if you want to optimize your code make sure that you are really tackling an actual bottleneck!

提交回复
热议问题