covariant return types when overriding

  • Thread starter Thread starter Sankar Nemani
  • Start date Start date
S

Sankar Nemani

Hi,
Does anyone know what the reason behind not allowing to
use "covariant return types when overriding methods in
derived classes" in C# is?
Also while other OO languages such as Java, don't allow
todo the same, why does C++ allow it and then the C# and
VB.NET don't allow?
I just want to understand the logical reasoning behind
this decision if there is one.

TIA
Srinivasa Sankar Nemani
 
Hello Sankar,
does C++ allow it and then the C# and VB.NET don't
allow? I just want to understand the logical
reasoning behind this decision if there is one.

I've wondered about this myself, but have not come to any
conclusions. This question has been asked before but I haven't seen an
'offical' answer yet. You can check the 'ask a language designer' page
on gotdotnet.com. The question was posted there over a year ago....
still no answer, but it might come someday.

http://www.gotdotnet.com/team/csharp/learn/columns/ask.aspx

Later,
Len
 
Sankar Nemani said:
Does anyone know what the reason behind not allowing to
use "covariant return types when overriding methods in
derived classes" in C# is?

I don't know, but I'd strongly suspect that it'll go away when generics
are introduced to C#, just as it's going away in Java in 1.5 as a
corollary of adding generics there.
 
Sankar,
I've wondered the same thing myself. The last time someone asked this, a
link was posted about why covariant return types don't work, but I don't
have that link handy.

If you want 'covariant return types' in .NET today, you can use Eiffel.

http://www.eiffel.com/

Of course only Eiffel code can make use of them, I'm not sure what happens
when you attempt to interop with normal .NET code.

I'm not sure if future versions of C# or VB.NET will include it, nor how
much of the CLR needs to support it for a language to fully support it.

Hope this helps
Jay
 
Back
Top