JEP 468 - binary compatibility clarifications
Gavin Bierman
gavin.bierman at oracle.com
Mon Apr 29 14:50:32 UTC 2024
Hi Atilla,
If you are asking about the binary compatibility of record classes, you can read the JLS:
13.4.27 Evolution of Record Classes
Adding, deleting, changing, or reordering record components in a record class may break compatibility with pre-existing binaries that are not recompiled; such a change is not recommended for widely distributed record classes.
More precisely, adding, deleting, changing, or reordering record components may change the corresponding implicit declarations of component fields and accessor methods, as well as changing the signature and implementation of the canonical constructor and other supporting methods, with consequences specified in §13.4.8 and §13.4.12.
In all other respects, the binary compatibility rules for record classes are identical to those for normal classes.
Gavin
On 25 Apr 2024, at 22:39, Attila Kelemen <attila.kelemen85 at gmail.com> wrote:
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/20240429/16f958b8/attachment-0001.htm>
More information about the amber-dev
mailing list