Return type covariance in Cooper

Hi,

Java supports return type covariance. For example, abstract method getItem of Adapter returns Object. In a descendant class it is possible to define getItem method with a “narrower” return type. Very handy. In Oxygene for Java it also compiles fine: in version 6 that is. Unfortunately, in version 7.1 it generates compiler error: (E122) Cannot instantiate abstract class.

Best regards,
Erwin

Can you give a simple example, please?

A simple example was needed indeed. It turns out that the example on Wikipedia of return type covariance generates compiler warning: warning W8: Method hides a method in parent class in Oxygene for Java 6.2.61.144. But at least it builds. Also in 7.1.73.1515.

I have included example of case with the abstract getItem method of Adapter where in a descendant class also a getItem method is defined with a more narrow return type. In Oxygene for Java 6.2.61.144 no compiler warnings. In Oxygene for Java 7.1.73.1515 two compiler warnings: warning W7: Type is treated as “abstract” as it has one or more abstract members and warning N6: Member “method getItem(arg1: Integer): Object” is abstract

These compiler warnings prohibit to instantiate class of course, which in Oxygene for Java v6.2 works fine. But in version 7.1.73.1515 generates build error: Cannot instantiate abstract class

org.me.testreturntypecovariance.zip (44.9 KB)

Best regards,
Erwin

Thanks, logged as bugs://68225: Return type covariance in Cooper

bugs://68225 got closed as fixed for release Andromeda Class

Great! Thanks.

I believe C# does not support return type covariance. Just curious, I have no license, but does RemObjects C# supports return type covariance now?

The post you refer to says explicitly c# doesn’t support it (well the .NET runtime doesn’t let you)