[records] Spec for next version of Record Classes JEP
Gavin Bierman
gavin.bierman at oracle.com
Mon Sep 28 10:21:09 UTC 2020
Dear all:
A draft of the specs for the Record Classes feature that we plan to finalize in
JDK 16 is now available:
http://cr.openjdk.java.net/~gbierman/8246771/latest/
[NB: The URL will change once we have a JEP number, and will be announced.]
The changes are the same as those in the second preview that was released in
Java SE 15, except for minor editorial changes and the following:
- To relax the current restriction on an inner class from declaring a member
that is explicitly or implicitly static. This will now be permitted and, in
particular, will allow an inner class to declare a record class member. (These
changes are detailed in the companion document "Local and Nested Static Declarations").
- Add text to explicitly rule out using C-style array declaration of record
components.
- Clarify that any annotations on record components that apply to the implicitly
declared accessor method must satisfy the existing rules for annotating a
method declaration.
- A new section (8.10.5) defining new restrictions on annotations of record
components to ensure that they are not lost.
This last point addresses the case highlighted by Tagir
(http://mail.openjdk.java.net/pipermail/amber-spec-experts/2020-September/002560.html).
There’s one minor corner-case that I bring to your attention. Consider the
following:
@Target(ElementType.METHOD)
@interface A { }
record R(@A int x) {
int x() { return this.x; }
}
The new rules ensure that this is an error as the annotation on the record
component is not propagated anywhere because of the explicit accessor
declaration. However, what if the accessor was annotated with the same
annotation?
@Target(ElementType.METHOD)
@interface A { }
record R(@A int x) {
@A int x() { return this.x; }
}
As it stands, the spec rules this out as an error. For simple annotations,
equality is simple to define, but do we want to attempt to define it for all
kinds of annotations? This feels like it’s not worth the complexity, but I’d be
happy to hear opinions.
Many thanks,
Gavin
More information about the amber-spec-experts
mailing list