Java Method invocation vs using a variable

前端 未结 14 2495
北海茫月
北海茫月 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:28

    If you keep the code evolution in mind, simple getters in v1.0 tend to become not-so-simple getters in v2.0.

    The coder who changes a simple getter to not-so-simple getter usually has no clue that there is a function that calls this getter 10 times instead of 1 and never corrects it there, etc.

    That's why from the point of view of the DRY principal it makes sense to cache value for repeated use.

提交回复
热议问题