[records] Spec for next version of Record Classes JEP
Tagir Valeev
amaembo at gmail.com
Tue Sep 29 15:50:24 UTC 2020
Hello!
Thank you for the spec update!
> However, what if the accessor was annotated with the same
annotation?
I would play simple: if the accessor exists, the METHOD-targeted
annotation is illegal, even if accessor is annotated in the same way.
In other words, to me, section 8.10.5 looks ok and doesn't require
changes. The only nit-pick is that it says "if a canonical constructor
is declared explicitly". However, from 8.10.4 one may derive that
compact constructor is a canonical constructor, so if compact
canonical constructor is explicitly declared then, per 8.10.5 it looks
like annotation should be discarded but it's not. Probably it's better
to write in 8.10.5 something like "if a non-compact canonical
constructor is declared explicitly". Well, probably I'm seeing things.
With best regards,
Tagir Valeev.
On Mon, Sep 28, 2020 at 5:21 PM Gavin Bierman <gavin.bierman at oracle.com> 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
More information about the amber-spec-experts
mailing list