Calling a getter multiple times or calling once and assigning to a variable?
Posted
by GK
on Stack Overflow
See other posts from Stack Overflow
or by GK
Published on 2010-05-12T17:16:25Z
Indexed on
2010/05/13
6:54 UTC
Read the original article
Hit count: 154
java
|premature-optimization
say suppose I have class as :
public class Age {
private int age;
public int getAge() {
return this.age;
}
}
In my Main class I am calling the getAge() method many times.
So I wanted to know is it advisable to call so many times or call once and assign it to some variable and use that variable.
Which is best and why?
© Stack Overflow or respective owner