Re: Method overrides and covariant return types
Isaac Gouy <[email protected]> Fri, 5 Mar 2004 13:07:11 -0800 (PST)
| Newsgroups | gmane.comp.lang.nice.general |
|---|---|
| Message-ID | <[email protected]> |
> By experience, we know that people _will_ write implicit overriding,
> and expect it to work, even though the documentation shows that
> method implementations have a different form.
IMO the language user doesn't benefit from having 2 different ways to
express explicit overriding - override keyword & yet another method
implementation form. Choose one - override keyword.
> The good part about it being a warning is that it leaves the
> choice to the new user to first focus on other errors he might get.
The good part about it being a warning is that it isn't an error!
Overriding is the default behaviour, the liklihood is that the code is
doing the correct thing, and the compiler is signaling *no more* than
the possibility that something else may have been intended.
As previously noted, the motivation for making overloading the default
in C# (instead of overriding) was performance. For version safety,
there are keywords to make both overloading and overriding explicit -
not using those keywords results in a warning message.
warning CS0108: The keyword new is required on 'B.doSomething()'
because it hides inherited member 'A.doSomething()'
warning CS0114: 'B.doSomething2()' hides inherited member
'A.doSomething2()'. To make the current member override that
implementation, add the override keyword. Otherwise add the new
keyword.
class A {
public void doSomething(){}
public virtual void doSomething2(){}
}
class B : A {
public void doSomething(){}
public void doSomething2(){}
}
class B2 : A {
public new void doSomething(){}
public override void doSomething2(){}
}
__________________________________
Do you Yahoo!?
Yahoo! Search - Find what youre looking for faster
http://search.yahoo.com
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click