What languages ​​support covariance on return types of inherited methods?

I initially asked this question , but when I found the answer, I found that my initial problem was the lack of support in C # for covariance on the types of the returned inherited methods. Upon learning about this, I was curious what languages ​​support this feature.

I agree with the answer of the one who can name the most.

EDIT : John Millikin correctly pointed out that many dynamic languages ​​support this. To clarify:

I am only looking for static / strongly typed languages.

+3
source share
7 answers
  • C ++
  • Java
  • REALbasic
  • Eiffel
  • Sather
  • Module 3
+4
source

, - Python, Ruby, Smalltalk, Javascript ..

+2

, , , .

# get() set()? , Leg get_leg() set_leg(DogLeg). : 1) get_leg() 2) underspecification set_leg().

0

++ .

0

Java 1.5. .

0

As noted by Ivan Hamilton and Mat Noguchi, C ++ supports this feature. But note that the covariant return types are broken down into template classes that inherit from some base in MSVC 7.X to 9.X (and probably also 6). You will get error C2555.

0
source

but I think that what I ask ... or is it?

I frankly do not know what you are asking. Obviously, Java has the same return type covariance support as C #, so if C # is missing what you are looking for, it also doesn't have Java.

-1
source

Source: https://habr.com/ru/post/1696704/


All Articles