[records] Specify use of @Override and @SafeVarargs on record components

Tagir Valeev amaembo at gmail.com
Sat Sep 19 09:23:09 UTC 2020


On Fri, Sep 18, 2020 at 10:40 PM Gavin Bierman <gavin.bierman at oracle.com> wrote:

> - It is annotated with the annotations, if any, that appear on the corresponding
>   record component and whose annotation types are applicable in the method
>   declaration context, or in type contexts, or both. **The rules for these
>   annotation modifiers, if any, on the accessor method are the same as for a
>   method declaration, and are specified in [9.7.4] and [9.7.5].**
> The last sentence is new, and mirrors what is said about normal method declarations in §8.4.3.
> What do you think?

I'm not very good in English but I'm fine if this statement
unambiguously imply that
if the annotation is not applicable to the method, then this is a
compilation error to put it on the record accessor.

Btw, we allowed Override on explicit accessors, so now it might be
unclear whether it's allowed on implicit ones.

Also what if we mark the record component with `@SafeVarargs` and
define an explicit accessor without this annotation? Like:

record X(@SafeVarargs int y) {
  public int y() {
    return y;

Is this acceptable? Javac 15 happily compiles this.

This brings more general question: is it allowed to put an annotation
that targeted to METHOD only if we define explicit accessor? In this
case, the annotation is not propagated anywhere and completely
disappears from the bytecode, even if it has CLASS/RUNTIME retention.
So probably this code should be rejected as mistaken? The same if the
annotation has PARAMETER target only and the explicit non-compact
canonical constructor is declared.

With best regards,
Tagir Valeev.

More information about the amber-spec-experts mailing list