Type parameters

Graydon Hoare graydon at mozilla.com
Wed Sep 6 17:11:54 PDT 2006


Peter Hall wrote:

> Not true. When you create an instance of the parametric container
> class, you will choose either Ducks or Artichokes to be the type of
> objects stored in the list. This means you will never be comparing
> Ducks to Artichokes unless one happens to extend the other...

Oh sure, but the compiler can't prove any of that. You still have to 
implement Duck.lessThan using a dynamic type check on the argument. The 
implementation of SortedList.<Duck> may, in fact, apply Duck.lessThan to 
an Artichoke. You have no way of knowing, it's statically unchecked.

Anyways, that just gives way to the second implementation -- that the 
compiler *can* prove some stuff about -- and in that case it has its own 
problems, as I pointed out.

-graydon



More information about the Es4-discuss mailing list