Reduce unnecessary memory usage | JSPsUse local variables, avoid inappropriate use of non-final getter methods
Accessing member data is slower than accessing a local variable, and calling a non-final or non-private getter method is even slower. There are sometimes good reasons to call non-final or non-private getter methods (it allows subclasses to override the getter behavior). Be sure that you use them with that in mind. However, calling the same non-final or non-private getter method twice in the same method is slower than necessary (and may have unintentional side effects since you cannot control the behavior of a subclass). Use a local variable to avoid calling the getter more than once per method call. For example, do this:
int total = 0; int amt = getAmount(); if (amt>0) { total += amt;}Not this:
int total = 0; if (getAmount()>0) { total += getAmount();}