I have been working with Java and C # for some time now, and I have asked myself this many times, but have not found the answer I was looking for.
When I need to call an object method (this means that it is not static), I have to use the call through an instance of the class, for example:
MyClass myInstance = new MyClass();
myInstance.nonStaticMethod();
I see this code everywhere, so I thought that if a single-line call (example below) behaves differently in terms of performance or just for the sake of standards?
This is what I had in mind in a single line call:
new MyClass().nonStaticMethod();
source
share