covariant return types when overriding

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
 
L

Len Weaver

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
 
J

Jon Skeet

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.
 
J

Jay B. Harlow [MVP - Outlook]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top