Marco Von Ballmoos writes:

> On Apr 7, 2008, at 09:28, Yossi Kreinin wrote:
>
>>> I would argue that more people would intuitively think that
>>> IList<B> inherits from IList<A> if B inherits from A than that it
>>> does not (and that generic methods are instead required).
>>
>> I think that the only reasonable test for "is Y a subclass of X?"
>> is "can I substitute Y objects whenever X objects are used?".
>> Y="collections of derived class objects" fails this test when
>> X="collections of base class objects".
>
>
> I agree with the test of "can I substitute Y objects whenever X
> objects are used?", but I don't follow -- in your example -- under
> which circumstances I would be unable to substitute IList<B> wherever
> IList<A> is expected.

Suppose you receive an IList<A> and try to append an instance of A to
it.  This operation is only valid on an instance of IList<B> if the
new object is also an instance of B.  There are probably other
instances of why covariance cannot cross container boundaries, but
that is an easy one to remember.

Michael Poole

Reply via email to