I came across this and it is throwing me off:
Prints false. But I dont understand why. By the time str1.equals( ... ) is called, str1 is pointing to the equivalent string in the pool.
Thank you Enthuware for this puzzler!
According to the JLS
At run time, method invocation requires five steps. First, a target reference may be computed. Second, the argument expressions are evaluated. Third, the accessibility of the method to be invoked is checked. Fourth, the actual code for the method to be executed is located. Fifth, a new activation frame is created, synchronization is performed if necessary, and control is transferred to the method code.
A similar question is:
Daniel Cox wrote: According to the JLS
Thanks Daniel for linking this document. I didn't really understand the run time blurb when I read it(and franky, I'm still not sure I do). But there's an example on that page and I'll paste in the explanation in case anyone else comes across this thread looking for the answer...
I've edited the method and variable names to match my question:
The occurrence of str1 before ".equals" is evaluated first, before the argument expression str1 = str2. Therefore, a reference to the string "one" is remembered as the target reference before the local variable str1 is changed to refer to the string "two". As a result, the equals method is invoked for target object "one" with argument "two", so the result of the invocation is false.
Daniel Cox wrote:For reference purposes, the example John is referring to is Example 126.96.36.199-2. Evaluation Order During Method Invocation
Thanks again, Daniel. I looked for an anchor tag but didn't find one.