Must you `override` when implementing an interface?

P T Withington ptw at
Mon Mar 26 11:35:12 PDT 2007

On 2007-03-26, at 14:11 EDT, Jeff Dyer wrote:

>> 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.
> It already does. In AS3/draft-ES4 it is a static error if any of the
> inherited interface methods is not implemented in the inheriting  
> class,
> unlike in Java. Partially implemented (or abstract) classes don't  
> exist
> in ES4.

I'm considering the case where I define a method that I think is part  
of an interface but it is not:

interface A {
   function x ();

class B implements A {
   function x () {...};
   function y () {...};

function (a:A) {

Possibly unlikely, and yes, you get an error at the call site, but if  
I had to say:

class B implements A {
   implement function x () {...};
   implement function y () {...};

The compiler could warn me that there is no interface method `y` in  
the interfaces implemented by B.  Perhaps useful in an IDE or where  
separate compilation is going on?  I'm comparing that to the override  
case where I declare a method as being an override but there is no  
such method in the super chain.

More information about the Es4-discuss mailing list