Type parameters

Peter Hall peterjoel at gmail.com
Wed Sep 6 17:06:56 PDT 2006


> As I said in the previous mail, "ISortable" and its kin are bad examples
> here. I'll give some details:
>
>    - The first implementation people aim for is this:
>
>      interface ISortable {
>         function lessThan(other: ISortable): bool;
>      }
>
>      This implementation is wrong because it suggests that one "sortable"
>      can meaningfully compare itself to all other sortables. If I make
>      Ducks and Artichokes both ISortable, the type system will not
>      prevent me from comparing them (and getting a runtime error).
>

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

var duckList:SortableList.<Duck> = new SortableList.<Duck>();


Peter



More information about the Es4-discuss mailing list