Type parameters

Peter Hall peterjoel at gmail.com
Tue Sep 5 15:58:09 PDT 2006

> > That means that in the implementation of Api you can call any method
> > defined in "Required". The type parameter is restricted to classes
> > "implementing" Required.
> Sure, but again this is a sort of vague example. In a lot of real
> examples, if you want an object of type "Required" that's actually *all*
> you need to know about the type; you don't need to name the subtype of
> "Required" because all you're going to do is call a few interface
> methods on it.

I don't think this is correct. It is true that, inside methods of Api,
you are only going to use methods of Required. But without type
restrictions Api couldn't call *any* methods without a lot of
unpleasant runtime tests and coercions. Clients of Api could quite
usefully parametrize it with several subtypes of Required, and gain
the benefit of type-safety when using the subtype functionality -
which is the whole point of parametrized types after all. So my
feeling is that lack of type restriction consigns parametrized types
to be used only for dumb collections (or objects that could be
constructed equivalently by aggregating such a collection).


More information about the Es4-discuss mailing list