Talk:Parameter covariance

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

When you're dealing with parameters rather than return types, it would make sense to have it going the other way: a function can be overridden such that a parameter takes a more general type. That is, you could have something like

class Shape {
    void doSomething(Triangle t);
}

class Triangle : Shape {
    void doSomething(Shape s);
}

This makes sense and would be 'safe' in the sense that the article uses the word. That is, Triangle's doSomething overrides Shape's doSomething, and can still take any Triangle as argument as specified in Shape.

Does this have a name? And does anyone know a language that implements it? -- Smjg 17:55, 31 May 2005 (UTC)[reply]

Found it! It's called contravariance. -- Smjg 18:59, 31 May 2005 (UTC)[reply]