Is calling a getter function in class that does not computation better than assign value to a new variable?
Example:
Class Test{
private AnotherClass a;
public AnotherClass getA(){
return a;
}
}
Is it better to keep calling getA() in a same function or todo AnotherClass var1 = getA(); then keep using var1 in that function.
I want to understand memory vs performance & how can we balance it.
Edit: Usage example: Consider another class being list
AnotherClass var1 = test.getA();
if(var1!=null){
for(List var : var1){
// do something
}
or
if(test.getA()!=null){
for(List var : test.getA())
// do something
}
Note this kind of behaviour can be done multiple time in multiple places.