[records] Summary so far
brian.goetz at oracle.com
Thu Mar 19 14:36:04 UTC 2020
>>> Q10. Special annotation for explicit declaration of accessors.
>>> Tagir  proposes a new `@RecordAccessor` annotation to mark explicit
>>> accessors, much as `@Override` is used to mark method overrides.
>>> A: Rather than introduce a new accessor, we will consider extending the
>>> meaning of the `@Override` annotation to include this case.
>> I agree, @Override is fine here even if it's not a real override (using @Override on an asbtract method of an interface is not a real override too so @Override doesn't mean @Override since Java 6 anyway).
> So, wouldn't this be confusing? For example, if a record declaration also declared that it implements an interface, you wouldn't know from the 1st glance whether such method is an explicit declaration of accessor or just implementation of the interface method or maybe both? Would someone mind?
I think its a question of which people would mind more.
A good analogy is extends vs implements. We’re used to that in classes, but in generic type bounds, `<T extends I>` is used both for classes and interfaces. And think how irritating it would be to say `<T extends C implements I>`. The distinction between “what kind of extension” is not really important here, and were the compiler to demand this, we’d rightly say it is being pedantic.
The alternatives to lumping “explicit implementation of mandated member” into @Override is to make up a new thing, or not allow you to say it at all. “Not at all” is a credible answer, but will make some people sad and they will continue to ask for it. A new thing seems like it is asking again users to make fine distinctions that don’t matter (and, if the mandated member is also an interface member, they should specify both? And, does it really matter?) An intuitive interpretation of “@Override” is “this is not a new method, it is a more refined declaration of a method I already have.” Which covers both override-from-super and explicitly-implement-mandated.
I think more people would mind having to make the distinction than not being able to make the distinction.
More information about the amber-spec-experts