Marco Von Ballmoos wrote:
On Apr 5, 2008, at 23:25, Aristotle Pagaltzis wrote:
* Marco Von Ballmoos <[email protected]> [2008-04-05 00:10]:
C#'s generics are better, but still forbid covariance

Have to, to ensure type safety.

It's a matter of opinion whether the absolute safety from such a slim possibility is worth the reduction of expressiveness.

My Java is quite rusty, but aren't Java methods supposed to declare their exceptions, and wouldn't a theoretical possibility of a ClassCastException thus be a problem with generic methods?

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".

Now, lots of actual OO users never use the substitutability test, hence the Rectangle classes derived from Triangle and vice versa. Should a language designer care about the intuition of these people?

Reply via email to