I’m curious to know if either of these two Java method invocations will behave differently at all in terms of processor time, memory allocation and/or garbage collection.
SomeObject myObj = new SomeObject();
myObj.doSomething();
vs.
new SomeObject().doSomething();
Looking at the generated bytecode:
You can clearly see that this one has two more instructions:
Those instructions seem very redundant and easy to optimize-out. I’d bet the JIT compiler would handle them if needed.