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.
-
Any dynamic languages, of course -- Python, Ruby, Smalltalk, Javascript, etc.
From John Millikin -
@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?
From Luke -
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.
From John Millikin -
Basically what I'm asking is what languages support what I'm trying to do here.
From Luke -
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()andset()methods? If not, I would split them into actualLeg get_leg()andset_leg(DogLeg)functions. Otherwise one of two things will happen: 1) overspecification ofget_leg()2) underspecification ofset_leg().From John Millikin -
C++ supports covariant return types.
MSN
From Mat Noguchi -
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!
From Luke -
- C++
- Java
- REALbasic
- Eiffel
- Sather
- Modula-3
From Ivan Hamilton -
Java added support for this in 1.5. It will not compile in earlier versions.
From John Meagher -
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.
From mlbrock
0 comments:
Post a Comment