Must you `override` when implementing an interface?

P T Withington ptw at pobox.com
Mon Mar 26 11:06:37 PDT 2007


The question came up in the context of documenting methods,  
distinguishing methods that are being defined in the class (and are  
not part of an interface).  In that sense, an `implement` attribute  
would have some of the benefit of `override` in catching type-ohs:   
the compiler could signal an error if you define a method as  
implementing an interface and there is no matching interface.

On 2007-03-26, at 13:45 EDT, Jeff Dyer wrote:

> 'override' is not allowed when implementing an interface method.
>
> We want to distinguish between overriding (redefining the behavior  
> of a
> method) and implementing (satisfying specific type constraints of a
> method). We could have an 'implements' attribute to mark methods doing
> the latter, but that seems like overkill since you'll get a "method  
> not
> implemented" error or type error if you don't get the name and type of
> the implementing method right.
>
> Sound reasonable?
>
> Jd
>
>> -----Original Message-----
>> From: es4-discuss-bounces at mozilla.org [mailto:es4-discuss-
>> bounces at mozilla.org] On Behalf Of P T Withington
>> Sent: Monday, March 26, 2007 10:27 AM
>> To: es4-discuss
>> Subject: Must you `override` when implementing an interface?
>>
>> A reader asks,
>>
>>> When I implement an interface method, must I specify the `override`
>>> attribute?
>>
>>  From the spec, I see:
>>
>>> It is an error to define a method without the override attribute if
>>> the name matches the name of an inherited method.
>>> Methods inherited from an interface must be implemented by a method
>>> with a name and signature that matches the inherited method.
>>> Interface methods are implemented by an instance method declared
>>> with the public attribute.
>> Taken together, I would conclude that the instance method must also
>> be declared with the `override` attribute.  Is that the intent?
>>
>> _______________________________________________
>> Es4-discuss mailing list
>> Es4-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es4-discuss
> _______________________________________________
> Es4-discuss mailing list
> Es4-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es4-discuss




More information about the Es4-discuss mailing list