Tutorial by Examples: contravariance

The - symbol marks a type parameter as contravariant - here we say that "Handler is contravariant on A": trait Handler[-A] { def handle(a: A): Unit } A contravariant type parameter can be thought of as an "input" type. Marking A as contravariant asserts that Handler[X] &l...
When is an IComparer<T> a subtype of a different IComparer<T1>? When T1 is a subtype of T. IComparer is contravariant in its T parameter, which means that IComparer's subtype relationship goes in the opposite direction as T's. class Animal { /* ... */ } class Dog : Animal { /* ... */ }...

Page 1 of 1