# Return type covariance in Cooper

**URL:** https://talk.remobjects.com/t/return-type-covariance-in-cooper/4403
**Category:** Elements Bugs
**Created:** [May 28, 2014, 5:09pm UTC](https://talk.remobjects.com/t/return-type-covariance-in-cooper/4403 "2014-05-28T17:09:33Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![erwin](https://talk.remobjects.com/user_avatar/talk.remobjects.com/erwin/32/8213_2.png) [@erwin](https://talk.remobjects.com/u/erwin)
#### Post date: [May 28, 2014, 5:09pm UTC](https://talk.remobjects.com/t/return-type-covariance-in-cooper/4403/1 "2014-05-28T17:09:33Z")

</div>

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](http://www.piwai.info/android-adapter-good-practices/). 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

---

<div class="post-metadata">

### Author: ![slavad](https://talk.remobjects.com/user_avatar/talk.remobjects.com/slavad/32/2_2.png) [@slavad](https://talk.remobjects.com/u/slavad)
#### Post date: [May 30, 2014, 9:14am UTC](https://talk.remobjects.com/t/return-type-covariance-in-cooper/4403/2 "2014-05-30T09:14:08Z")

</div>

Can you give a simple example, please?

---

<div class="post-metadata">

### Author: ![erwin](https://talk.remobjects.com/user_avatar/talk.remobjects.com/erwin/32/8213_2.png) [@erwin](https://talk.remobjects.com/u/erwin)
#### Post date: [May 31, 2014, 11:20am UTC](https://talk.remobjects.com/t/return-type-covariance-in-cooper/4403/3 "2014-05-31T11:20:39Z")

</div>

A simple example was needed indeed. It turns out that the [example](http://en.wikipedia.org/wiki/Covariant_return_type) 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](https://talk.remobjects.com/uploads/default/412/29d5dec5b03b4485.zip) (44.9 KB)

Best regards,  
Erwin

---

<div class="post-metadata">

### Author: ![RemObjectsSoftware](https://talk.remobjects.com/user_avatar/talk.remobjects.com/remobjectssoftware/32/15947_2.png) [@RemObjectsSoftware](https://talk.remobjects.com/u/RemObjectsSoftware)
#### Post date: [June 2, 2014, 7:11am UTC](https://talk.remobjects.com/t/return-type-covariance-in-cooper/4403/4 "2014-06-02T07:11:46Z")

</div>

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

---

<div class="post-metadata">

### Author: ![RemObjectsSoftware](https://talk.remobjects.com/user_avatar/talk.remobjects.com/remobjectssoftware/32/15947_2.png) [@RemObjectsSoftware](https://talk.remobjects.com/u/RemObjectsSoftware)
#### Post date: [July 17, 2014, 4:07pm UTC](https://talk.remobjects.com/t/return-type-covariance-in-cooper/4403/5 "2014-07-17T16:07:43Z")

</div>

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

---

<div class="post-metadata">

### Author: ![erwin](https://talk.remobjects.com/user_avatar/talk.remobjects.com/erwin/32/8213_2.png) [@erwin](https://talk.remobjects.com/u/erwin)
#### Post date: [July 18, 2014, 5:01am UTC](https://talk.remobjects.com/t/return-type-covariance-in-cooper/4403/6 "2014-07-18T05:01:17Z")

</div>

Great! Thanks.

I believe [C# does not support return type covariance](http://stackoverflow.com/questions/5709034/does-c-sharp-support-return-type-covariance). Just curious, I have no license, but does RemObjects C# supports return type covariance now?

---

<div class="post-metadata">

### Author: ![ck](https://talk.remobjects.com/user_avatar/talk.remobjects.com/ck/32/8740_2.png) [@ck](https://talk.remobjects.com/u/ck)
#### Post date: [July 18, 2014, 7:09am UTC](https://talk.remobjects.com/t/return-type-covariance-in-cooper/4403/7 "2014-07-18T07:09:58Z")

</div>

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