[records] Spec for next version of Record Classes JEP

Brian Goetz brian.goetz at oracle.com
Tue Sep 29 21:32:55 UTC 2020


In 6.1, you allude to implicitly declared fields of a record, but not 
implicitly declared accessor methods or constructors.  Is this an omission?

In 8.1.1, I see local records and enums (and they are static), but I 
don't see local interfaces.  I assume we are saving those for a future 
pass (along with static members in inner classes?)

Should @SafeVarargs be allowed to be applied to a varargs record?  
Should it get propagated to the constructor in that case?  Or do we just 
have people declare a compact constructor with @SafeVarargs?  What is 
the correct use of @SV for varargs records?


On 9/28/2020 6:21 AM, Gavin Bierman wrote:
> 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20200929/6ebc677a/attachment.htm>


More information about the amber-spec-experts mailing list