Re: Why are there no covariant return types?

From: Stoitcho Goutsev \(100\) [C# MVP] (100_at_100.com)
Date: 07/05/04


Date: Mon, 5 Jul 2004 09:34:52 -0400

Hmm, there are always cases where something can be useful. I said in theory
becuse I can't see any possible way to know what is the type in this
situation

void Foo(ArrayList list)
{
    XXX copy = list.Clone();

    //What is XXX? The simple answer is ArrayList. But is it?

}

A dont see many cases where you create a list and cloned. Normaly you
received as a parameter or it is property of some object. In this case you
cannot know.

-- 
Stoitcho Goutsev (100) [C# MVP]
"Stefan Slapeta" <stefan_nospam_@slapeta.com> wrote in message
news:cc3abs$h7c$2@paperboy.Austria.EU.net...
> Stoitcho Goutsev (100) [C# MVP] wrote:
>
> > Yeah, besides the fact that theoretically you don't know the type of the
> > object, which Clone methods you call.
> >
> > And again in theory one should go with the most generic base type and
then
> > do the conversion.
> >
>
> In theory, you should avoid any cast if possible because every cast is a
> potential runtime error!
>
> And here - *with* covariant return types - you *for sure* know what
> class you are dealing with *and* you can avoid any cast.
>
> ArrayList original;
> ArrayList copy = original.Clone();
>
>
> Stefan


Relevant Pages

  • Re: Convert short to float
    ... >> avoid redundant casting if code compiles without ... > for an error, disable the warning (using a pragma, not a ... If you use a cast and later change the type ... it's quite dificult to avoid ...
    (microsoft.public.vc.language)
  • Re: WIN32_FIND_DATA and gigantic file sizes
    ... Note this is a case of failing to cast properly; ... these horrible low/high DWORD pairs, ... MVP Tips: http://www.flounder.com/mvp_tips.htm ...
    (microsoft.public.vc.mfc)
  • Re: [PATCH] libata: Avoid overflow in ata_tf_read_block() when tf->hba_lbal > 127
    ... sign extension bug that was fixed in commit ba14a9c2 ("libata: Avoid ... Fix this by adding a cast to u64. ...
    (Linux-Kernel)
  • Re: find class of a class instance
    ... Isn't polymorphism (virtual functions) what you would use to eliminate the ... MVP Tips:http://www.flounder.com/mvp_tips.htm ... track of a list of CPerson objects. ... so I can cast the object accordingly for data processing. ...
    (microsoft.public.vc.mfc)
  • required hack for Xeon 64
    ... to make in order to avoid the following message: ... Run-Time Check Failure #1 - A cast to a smaller data type has caused a loss ... you should mask the source of the cast ...
    (comp.lang.tcl)