Re: Method overrides and covariant return types
Daniel Bonniot <[email protected]> Fri, 05 Mar 2004 00:18:25 +0100
| Newsgroups | gmane.comp.lang.nice.general |
|---|---|
| Message-ID | <[email protected]> |
>I tested all the examples I posted from the "Covariant Return Types" thread and
>they all seemed to work fine, except for one (see below). In addition, I did all
>these tests on the JDK 1.5 beta and there were no JDK 1.5-related problems. But,
>that is very limited testing.
>
>
OK, thanks for the info.
>I think that the warning should be changed to an error. That is, your code
>should not compile if it is using implicit overriding.
>
>
Yes, this is a matter of taste. The advantage of a warning is that it
leaves open the possibility to use the implicit style if you prefer it
(an option to suppress or enable some warnings seems acceptable, while
an option that actually change the behaviour of the compiler in
accepting some construct or not feels really wrong). Warnings seem
appropriate for situations which, while not stricly incorrect (leading
to runtime errors), are possibly hiding a mistake.
Anyway, changing this warning to an error or on the contrary allowing
both styles could be reached smoothly from the current situation, so we
can take some time to gather experience about this, especially from the
input of newcomers.
>There is still one problem. If you have overloaded a method in such a way that
>it _could_ override another method, then the compiler _forces_ the overriding.
>That is, I can't find a way to say "This method does not override a method with
>the same name and with contravariant parameters," like in f.doSomethingElse(B)
>below.
>
>
I think that the current behaviour is desirable. Having a method that
could override another, but actually performs an action that is not
acceptable for the original method is plain confusing. In that case, you
are most likely better off making the difference obvious in choosing a
descriptive distinct name for the new method.
>override B doSomething(B a) { }
>// This isn't supposed to override anything
>void doSomethingElse(B b) { }
>
>
(anyway, this is supposed to give you a warning or error. so you would
need an explicit way about _not_ overriding...)
Daniel
-------------------------------------------------------
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