In addition to Andrey’s reply (which I agree with, +1) – when ICloneable
is done, you can also choose explicit implementation to make the public Clone()
return a typed object:
public Foo Clone() { /* your code */ }
object ICloneable.Clone() {return Clone();}
Of course there is a second issue with a generic ICloneable<T>
– inheritance.
If I have:
public class Foo {}
public class Bar : Foo {}
And I implemented ICloneable<T>
, then do I implement ICloneable<Foo>
? ICloneable<Bar>
? You quickly start implementing a lot of identical interfaces…
Compare to a cast… and is it really so bad?