Timeline for Argument contravariance, real world purpose and usage?
Current License: CC BY-SA 3.0
6 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jan 30, 2018 at 15:38 | comment | added | Erik Eidt | There is another example in that article: The Circle class inherits Shape and overrides Area. The example creates a SortedSet<T> of Circle objects, using a constructor that takes an IComparer<Circle>. However, instead of passing an IComparer<Circle>, the example passes a ShapeAreaComparer object, which implements IComparer<Shape>. The example can pass a comparer of a less derived type (Shape) when the code calls for a comparer of a more derived type (Circle), because the type parameter of the IComparer<T> generic interface is contravariant. | |
| Jan 30, 2018 at 14:57 | history | edited | Joel Harkes | CC BY-SA 3.0 | added 281 characters in body |
| Jan 30, 2018 at 14:55 | history | edited | Deduplicator | CC BY-SA 3.0 | added 25 characters in body |
| Jan 30, 2018 at 14:54 | comment | added | Joel Harkes | if CatShelter implementation would also be able to store Objects. (this class is also used directly, not through interface) then you don't need another method to implement the interface. | |
| Jan 30, 2018 at 14:49 | comment | added | John V | I can see even WIkipedia describes that with the CatShelter example, which in derived class accepts the Animal type (en.wikipedia.org/wiki/…). But I just cannot see jhow this is useful and why | |
| Jan 30, 2018 at 14:32 | history | answered | Joel Harkes | CC BY-SA 3.0 |