Re: Why are there no covariant return types?
From: Stoitcho Goutsev \(100\) [C# MVP] (100_at_100.com)
Date: 07/05/04
- Next message: Scott Allen: "Re: Why FXCop recommends me not to do this way of method calling?"
- Previous message: Mark Broadbent: "Re: Creating COM objects"
- In reply to: Stefan Slapeta: "Re: Why are there no covariant return types?"
- Messages sorted by: [ date ] [ thread ]
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
- Next message: Scott Allen: "Re: Why FXCop recommends me not to do this way of method calling?"
- Previous message: Mark Broadbent: "Re: Creating COM objects"
- In reply to: Stefan Slapeta: "Re: Why are there no covariant return types?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|