Paul Clapham wrote:To compare the two versions you must assume that "getMyObject()" returns the same object every time you call it. If that isn't the case then the two versions don't necessarily do the same thing.
Ulf Dittmer wrote:The 2nd approach should be faster, but whether that makes a noticeable difference depends on how complex the getMyObject method is.