A Question about optimization

Jul 3, 2013 at 10:27pm
Im writing a program that uses classes and i was wondering which is more effecient for accessing a classes private fields. calling a public method as in

someClass.getVal();

numerous times, or copying over that value to the function running it so it only has to make that call once and it can be used numerous times?

thanks for the help

Jul 3, 2013 at 10:35pm
If you're going to be using the value multiple times and it's not changing, it's more efficient to copy it to a local variable and use the local variable.

Jul 3, 2013 at 10:38pm
Allright, Thank you :D
Topic archived. No new replies allowed.