Re: Why are there no covariant return types?
From: Stoitcho Goutsev \(100\) [C# MVP] (100_at_100.com)
Date: 07/01/04
- Next message: Greg Oetker: "User Control"
- Previous message: Christoph Nahr: "[ANN] Tektosyne Library 2.6.0 released"
- In reply to: Jon Skeet [C# MVP]: "Re: Why are there no covariant return types?"
- Next in thread: Stefan Slapeta: "Re: Why are there no covariant return types?"
- Reply: Stefan Slapeta: "Re: Why are there no covariant return types?"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 1 Jul 2004 10:23:32 -0400
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.
---
Stoitcho Goutsev (100) [C# MVP]
"Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
news:MPG.1b4d609128dd0b9698ae12@msnews.microsoft.com...
> Stoitcho Goutsev (100) [C# MVP] <100@100.com> wrote:
> > Could you give us some real life example of where you could use that.
>
> Here's a *really* simple example: ICloneable.
>
> ICloneable defines Clone's return type to be object, when actually you
> almost *always* end up casting the result to the type you know it will
> be - the same type as the instance you're calling it on.
>
> So, if I want to clone an ArrayList, I need:
>
> ArrayList copy = (ArrayList) original.Clone();
>
> If ArrayList could have declared
>
> ArrayList Clone()
> {
> ...
> }
>
> we wouldn't need to do this.
>
> Now in fact, this *is* done all over the framework already, using
> explicit interface implementation - look at the various database
> classes (SqlConnection, SqlCommand etc). It's a nasty hack around the
> lack of covariant return types, and it would have been much nicer if a
> single method could have been declared, instead of one for the generic
> version and one for the concrete subtype.
>
> --
> Jon Skeet - <skeet@pobox.com>
> http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too
- Next message: Greg Oetker: "User Control"
- Previous message: Christoph Nahr: "[ANN] Tektosyne Library 2.6.0 released"
- In reply to: Jon Skeet [C# MVP]: "Re: Why are there no covariant return types?"
- Next in thread: Stefan Slapeta: "Re: Why are there no covariant return types?"
- Reply: Stefan Slapeta: "Re: Why are there no covariant return types?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|