Re: Why are there no covariant return types?

From: Stefan Slapeta (stefan_nospam__at_slapeta.com)
Date: 07/02/04


Date: Fri, 02 Jul 2004 11:35:57 +0200

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: Why are there no covariant return types?
    ... Stoitcho Goutsev [C# MVP] ... > Stoitcho Goutsev wrote: ... you should avoid any cast if possible because every cast is a ... > class you are dealing with *and* you can avoid any cast. ...
    (microsoft.public.dotnet.languages.csharp)
  • 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: [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)
  • 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)
  • Re: Should you simplify this code? Write only code
    ... You don't cast to avoid the compiler error - you either call ToList ... and the examples given in books ...
    (microsoft.public.dotnet.languages.csharp)