I have more of a "how much is too much" question. I have a Java class that defines several getters/setters for use by external classes (about 30 altogether). However, the Java class itself requires the use of these variables as well in some cases.
I understand the concept of using member fields instead of the getter methods within a class, but the getters in this case perform a function (unmasking an integer to be specific) to create the value to be returned.
So from a performance and memory reduction perspective, for the few calls within the class that need those values, I'm curious if I should...
a. Just call the getter
b. Do the unmasking wherever I need the values throughout the class, just like the getter
c. Create variables to hold those values, load these up by calling all the getters on startup, and use those within the class (30 or so integers may not be a serious memory risk, but I would also need to add to my code to keep those updated if a user sets new values...since the value is updated and masked).
Any thoughts are appreciated!
a) Call the getter - as you pointed out it's the right and clean way in your case.
b) and c) would be premature optimization and most likely do more harm than good (unless you REALLY know that this particular spot will be a hot spot in your code AND your JIT-compiler will not be able to optimize it for you).
If you really hit performance problems at some point, then profile the application and optimize only hot spots manually.