I was wondering whether it was more efficient to use get() excessively on an object or store the return of the get() in a variable and use that. For example, would it be more efficient to do this:someObject.setColor(otherObject.getColor().r, otherObject.getColor().g,otherObject.getColor().b);or to store the it in a variable like thisColor color = otherObject.getColor();someObject.setColor(color.r, color.g, color.b);
Regardless of what's most efficient, I'm pretty sure choosing the least efficient will never be the primary bottleneck in anything you code.
I don't know about efficiency from a performance point of view, but from a readability (and typing) point of view, the second approach is better
Can you explain why in option two it does not rely on optimizations by the java run time?
someFolk the possible optimization in option 1 is that the call to otherObject.getColor() is done only once, and the returned object is stored in a temporary variable. The java runtime might do that for you, or you do it explicitly for yourself as in option 2.