views:

344

answers:

10

I discovered that the cause of my problems (see question) was the lack of support in C# for covariance on inherited methods' return types. Now I'm curious what languages support this feature. Accepted answer will be whoever can name the most.

EDIT: John Millikin correctly pointed out that lots of dynamic languages support this. I'll have to clarify that I'm looking for static/strongly typed languages.

+2  A: 

Any dynamic languages, of course -- Python, Ruby, Smalltalk, Javascript, etc.

John Millikin
A: 

@John Millikin I see that you removed Java from the list because "Java only allows it for objects in the same inheritance hierarchy" but I think thats what I'm asking for..or is it?

Luke
A: 

but I think thats what I'm asking for..or is it?

I frankly don't know what you're asking. Java apparently has the same support for return-type covariance as C#, so if whatever you're looking for is lacking in C#, it's lacking in Java also.

John Millikin
A: 

Basically what I'm asking is what languages support what I'm trying to do here.

Luke
A: 

Basically what I'm asking is what languages support what I'm trying to do here.

Does C# let you specify different data types for the get() and set() methods? If not, I would split them into actual Leg get_leg() and set_leg(DogLeg) functions. Otherwise one of two things will happen: 1) overspecification of get_leg() 2) underspecification of set_leg().

John Millikin
A: 

C++ supports covariant return types.

MSN

Mat Noguchi
A: 

Yeah originally when I asked that it was methods..I don't think its really possible with properties since covariance on the parameter type would not work. I'm going to update that question to be functions again. Sorry if I sucked you into an unanswerable question!

Luke
+2  A: 
  • C++
  • Java
  • REALbasic
  • Eiffel
  • Sather
  • Modula-3
Ivan Hamilton
A: 

Java added support for this in 1.5. It will not compile in earlier versions.

John Meagher
A: 

As pointed out by Ivan Hamilton and Mat Noguchi, C++ supports the feature. But note that covariant return types are broken for template classes which inherit from some base in MSVC 7.X through 9.X (and probably 6 also). You get error C2555.

mlbrock