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

Tagir Valeev amaembo at gmail.com
Wed Jan 22 08:03:36 UTC 2020


It appears that it's possible to annotate record component as
@Override or @SafeVarargs, and spec doesn't explicitly forbid this:

record Test(@SafeVarargs int x, @Override int y) {}

In these cases, it's assumed that the annotation propagates to the
accessor method. However, having @SafeVarargs on the accessor method
is prohibited, so should be in a record component. So I expect to see
in something like this:

> It is a compile-time error if a record component (§8.10.1) is annotated with the annotation @SafeVarargs.

Having the @Override is possible on the accessor if accessor overrides
the interface method (and it's really cool possibility!) Probably it's
ok to allow this annotation on the record component in this case, but
it should be definitely disallowed if the accessor doesn't override
anything. So I expect something like this in

> If a record component (§8.10.1) of record R is annotated with the annotation @Override and the accessor method for that component (§8.10.3) does not override a method declared in a superinterface of R (§, then a compile-time error occurs.

What do you think?

With best regards,
Tagir Valeev.

[1] https://docs.oracle.com/javase/specs/jls/se13/html/jls-9.html#jls-
[2] https://docs.oracle.com/javase/specs/jls/se13/html/jls-9.html#jls-

More information about the amber-spec-experts mailing list