DRAFT
CallRequiresVariable
Incorrect
One needs a variable to invoke a method
Correct
CorrectionHere is what's right.
Here is what's right.
One can invoke a method on an object without the reference to that object being stored in a variable. All that is needed is that the expression in front of the ”.” of the call evaluates to an object reference.
For example, one can do method chaining on a normal method:
get().m(); // assuming get() returns an object
Or one can do method chaining on a constructor:
new C().m();
Or one can call a method on an String
literal:
"Hi".toString();
Or one can call a method on an object one gets out of an array:
a[0].m();
Language
Java
Concepts
Expressible In
Literature References
The following papers directly or indirectly provide qualitative or quantitative evidence related to this misconception.