I agree it is silly to put these annos on record components. On the other > hand, I am not sure the spec should prohibit them -- seems more the sort of > thing an IDE should say "hey, that was probably dumb, are you sure you want > that?" > > In any case, it is reasonable for a compiler to error in the case of > @Override on a component whose accessor does not override something -- > because we should type-check implicit members as well as explicit. >
The same argument applies to @SafeVarargs. The compiler will implicitly apply it to the accessor method but according to the spec, this annotation cannot be applied to non-vararg method, and accessor method is never vararg, hence this should be an error. I feel this should be covered by spec because @SafeVarargs is fully specified in any other aspect. E. g. it's equally silly to put it on the method without arguments and it's a compilation error, not just IDE warning. With best regards, Tagir Valeev. > > > > On 1/22/2020 3:03 AM, Tagir Valeev wrote: > > 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 > > >