JEP 468 - binary compatibility clarifications

Attila Kelemen attila.kelemen85 at gmail.com
Thu Apr 25 21:39:40 UTC 2024


Hi,

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?

For better understanding, let me write down a specific example:

MyRecord.java (v1)
```
public record MyRecord(int x, int y) { }
```

MyRecord.java (v2)
```
public record MyRecord(int x, int y, int z) { }
```

MyRecord.java (v3)
```
public record MyRecord(int x, int y, int z) {
  public MyRecord(int x, int y) { this(x, y, 0); }
}
```

Let's suppose we have the following class which we compile against v1 of
`MyRecord`, and then never recompile:

```
public class MyClass {
  public static MyRecord adjustX(MyRecord src) {
    return src with { x = 9; }
  }
}
```

Now my question is: What is the output of the following code?

```
System.out.println(MyClass.adjustX(new MyRecord(1, 2, 3)).z());
```

A, When running with v2 of `MyRecord` on the classpath
B, When running with v3 of `MyRecord` on the classpath.

Thanks,
Attila
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20240425/e2d8c06b/attachment-0001.htm>


More information about the amber-dev mailing list