<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <font size="4" face="monospace">Gavin answered for the spec; I'll
      answer now for the implementation.  <br>
      <br>
      The current implementation will try to do an `invokespecial` of
      the (int, int) constructor, which will succeed with v1 and v3, but
      not v2.  It will also "inline" the (int, int) record pattern
      (shredding it into an instanceof test, and calls to accessors),
      which, once compiled, will work against v1/v2/v3.  <br>
      <br>
      When we get to reconstruction expressions for ordinary classes,
      the pattern part will work like the constructor part today,
      assuming that you declared an explicit deconstructor in v3.  <br>
      <br>
      <br>
    </font><br>
    <div class="moz-cite-prefix">On 4/25/2024 5:39 PM, Attila Kelemen
      wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:CAKDaPBd9DOX3J3Ceab5qNC3mezTyY1HFJEJ4F-hDXUUkN9zFXg@mail.gmail.com">
      
      <div dir="ltr">Hi,
        <div><br>
        </div>
        <div>Reading the JEP I'm unsure about some behavior when the
          record is recompiled with an additional component, while the
          code containing the `with` block is not. Can this be clarified
          in the JEP? Or is this undefined for now?</div>
        <div><br>
        </div>
        <div>For better understanding, let me write down a specific
          example:</div>
        <div><br>
        </div>
        <div>MyRecord.java (v1)</div>
        <div>```</div>
        <div>public record MyRecord(int x, int y) { }</div>
        <div>```</div>
        <div><br>
        </div>
        <div>
          <div>MyRecord.java (v2)</div>
          <div>```</div>
          <div>public record MyRecord(int x, int y, int z) { }</div>
          <div>```</div>
        </div>
        <div><br>
        </div>
        <div>
          <div>MyRecord.java (v3)</div>
          <div>```</div>
          <div>public record MyRecord(int x, int y, int z) {</div>
          <div>  public MyRecord(int x, int y) { this(x, y, 0); }</div>
          <div>}</div>
          <div>```</div>
        </div>
        <div><br>
        </div>
        <div>Let's suppose we have the following class which we compile
          against v1 of `MyRecord`, and then never recompile:</div>
        <div><br>
        </div>
        <div>```</div>
        <div>public class MyClass {</div>
        <div>  public static MyRecord adjustX(MyRecord src) {</div>
        <div>    return src with { x = 9; }</div>
        <div>  }</div>
        <div>}</div>
        <div>```</div>
        <div><br>
        </div>
        <div>Now my question is: What is the output of the following
          code?</div>
        <div><br>
        </div>
        <div>```</div>
        <div>System.out.println(MyClass.adjustX(new MyRecord(1, 2,
          3)).z());</div>
        <div>```</div>
        <div><br>
        </div>
        <div>A, When running with v2 of `MyRecord` on the classpath</div>
        <div>B, When running with v3 of `MyRecord` on the classpath.<br>
        </div>
        <div><br>
        </div>
        <div>Thanks,</div>
        <div>Attila</div>
        <div><br>
        </div>
      </div>
    </blockquote>
    <br>
  </body>
</html>