method returning child, doesn't overrides declared method returning parent
Steven Schveighoffer
schveiguy at yahoo.com
Tue Aug 30 03:47:03 PDT 2011
On Mon, 29 Aug 2011 16:24:46 -0400, Jonathan M Davis <jmdavisProg at gmx.com>
wrote:
> On Monday, August 29, 2011 14:09 Mariusz Gliwiński wrote:
>> <code>
>> interface Interface {
>> Interface method();
>> }
>> class Class : Interface {
>> override Class method() {}
>> }
>> </code>
>>
>> DMD complains it isn't overriding. How should it be according to
>> specification, and how about making it legal?
>
> It's _not_ overriding. It's implementing an interface method. Those are
> two
> totally different things. And I think that it's horrible that Java
> considers
> implementing an interface method as overriding it. I'd _hate_ to see
> that in
> D.
Then this must be a bug?
interface I
{
void foo();
}
class C : I
{
override void foo(); // compiles
}
I feel override should be *allowed* when implementing interface functions
(but not required). Otherwise, you get into situations where a base class
decides to become abstract (doesn't implement a function), but a derived
class is specifying override (especially if override is required, as is
planned), if that's a compiler error, I think it's a useless error.
-Steve
More information about the Digitalmars-d
mailing list