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
It is not worth if it is just getFoo()
. By caching it into a temp variable you are not making it much faster and maybe asking for trouble because getFoo()
may return different value later. But if it is something like getFoo().getBar().getBaz().getSomething()
and you know the value will not be changed within the block of code, then there may be a reason to use temp variable for better readability.