How can we have a variable that is writable within the class but only \"readable\" outside it?
For example, instead of having to do this:
Class
from what I know the compiler does not optimize this kind of code
The Hotspot JIT compiler most definitely does.
I was wondering what's the best solution?
Stop optimizing prematurely. If you're using this code in a painting routine, I can guarantee that the actual painting will take at least a hundred times longer than calling a trivial method, even if it's not inlined.