by Clee681 · 10y ago · 0 comments
Does the fact that Java is "pass by value" explain why the reassignment of "obj" does not change the output of re-invoking the method ref?
someExpression()::methodName
I mentally rewrite it into: getMethodReference(someExpression(), "methodName")
Where there is some fictional getMethodReference function that takes an object and a method name, and creates a reference. It works like this even when someExpression() is just a reference to a variable.In the rewritten form, someExpression() gets fully evaluated before getMethodReference is called, producing a value, and it's that value which is used to create the reference. As you suggested, it works like that because Java is pass-by-value.
If Java was pass-by-reference, then someExpression() would produce a reference to a variable instead of a value, and the reference could somehow be based on that variable. But it doesn't, so it's not.