Gary Whatmore wrote: > What's the difference between: > > type polymorphism > parametric polymorphism > ad-hoc polymorphism > generics > c++ templates > d style templates > other templates (are there?) > > Does Java and C# have type polymorphism or generics or templates? What's > the real name and how to compare? Is D most expressive? I bet it is. > > - G.W. >
>From what I've read, the more general term is parametric polymorphism which is broader than the Ada/C++ family of implementations (generics/templates). One big difference is that generics are explicit or nominative, whereas templates are implicit. In Java, Ada and C# you can only use features of the generic parameters you explicitly constrain, while in C++ and D the type checking is instead done at instantiation time, not based on the name but on the structure of the code. This makes it more flexibele, the argument for explicit polymorphism is that it has better type checking. Other ways to compare include: - what can be parametrized. Usually classes, interfaces and functions, D can also parametrize more declarations at once. - what kinds can serve as parameters. In Java and C# I think this is only types, D expands that range to include values, symbols and function literals. - support for implicit instantiation http://en.wikipedia.org/wiki/Type_polymorphism and a somewhat lighter read: http://www.artima.com/intv/generics.html