[records] Specify use of @Override and @SafeVarargs on record components
Tagir Valeev
amaembo at gmail.com
Wed Jan 22 08:03:36 UTC 2020
Hello!
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 9.6.4.7 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 9.6.4.4:
> 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 (§8.4.8.1), 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-9.6.4.7
[2] https://docs.oracle.com/javase/specs/jls/se13/html/jls-9.html#jls-9.6.4.4
More information about the amber-spec-experts
mailing list