<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Hello,</p>
    <p>the JLS 23 ยงย 15.26 "Assignment Operators" [1] says this about the
      result of assignments:</p>
    <p> </p>
    <blockquote type="cite">Thus, <code class="literal">a=b=c</code>
      means <code class="literal">a=(b=c)</code>, which assigns the
      value of <code class="literal">c</code> to <code class="literal">b</code>
      and then assigns the value of <code class="literal">b</code> to <code
        class="literal">a</code>. </blockquote>
    <blockquote type="cite">At run time, the result of the assignment
      expression is the value of the variable after the assignment has
      occurred.</blockquote>
    <p>This creates some ambiguity because these sentences sound as if
      there is (or at least there is permitted to be) an additional read
      of the assigned variable. That is, <code class="literal">a=b=c</code>
      is equivalent to:<br>
      ```<br>
      b = c<br>
      a = b<br>
      ```</p>
    <p>However, what is actually happening is (if I understand it
      correctly):<br>
      ```<br>
      temp = c<br>
      b = temp<br>
      a = temp<br>
      ```<br>
      (respectively the compiler just emits a `dup` before assigning the
      value to the variables)<br>
    </p>
    <p>This does make a difference for concurrent programs where a racy
      write is (intentionally) happening to the intermediate variable,
      in the example above 'b'.</p>
    <p>Therefore it would probably be good to reword that JLS section,
      or clarify that the assigned variable is not read again for the
      result value (unless JVMs are actually permitted to do that).<br>
    </p>
    <p><br>
    </p>
    <p>[1] <a class="moz-txt-link-freetext"
href="https://docs.oracle.com/javase/specs/jls/se23/html/jls-15.html#jls-15.26"
        moz-do-not-send="true">https://docs.oracle.com/javase/specs/jls/se23/html/jls-15.html#jls-15.26</a><br>
    </p>
  </body>
</html>