I originally asked this question , but in finding an answer, discovered that my original problem was a lack of support in C# for covariance on inherited methods' return types. After discovering that, I became curious as to what languages do support this feature.
I will accept the answer of whoever can name the most.
EDIT : John Millikin correctly pointed out that lots of dynamic languages support this. To clarify:
I am only looking for static/strongly typed languages.
任何动态语言,当然 - Python,Ruby,Smalltalk,Javascript等。
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()
.
C ++支持协变返回类型。
Java added support for this in 1.5. It will not compile in earlier versions.
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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.