maybe it’s dumb but is there a difference between
new Something().method();
and
Something tmpSomething = new Something();
tmpSomething.method();
as I was calling only one method on this particular object, I chose the first solution but I’m not sure that this is exactly the same behavior…
I just want to mention the constructor initializes a Writer and method writes in this file…
I did a quick test. This is the extremely trivial test code:
Javap shows that the two methods are compiled differently; chaining doesn’t touch the local variable table whereas the temporary variable does indeed stick around until the method returns. However, the VM/JIT compiler may still perform liveness analysis and allow the instance to be garbage collected before the method returns.