JEP 468 - binary compatibility clarifications
Brian Goetz
brian.goetz at oracle.com
Mon Apr 29 15:32:16 UTC 2024
Gavin answered for the spec; I'll answer now for the implementation.
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.
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.
On 4/25/2024 5:39 PM, Attila Kelemen 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/afe174a5/attachment.htm>
More information about the amber-dev
mailing list