Chapter 18
Generics
Yet another form of polymorphism is provided by the facility known as a generic (in C++, a template). Generics provide a way of parameterizing a class or a function by use of a type, just as normal parameters to a function provide a way to define an algorithm without identifying specific values.
With generics, a name is defined as a type parameter. This parameter can then be used within the class definition just as if it were a type, although no properties of the type are known when the class description is being read by the compiler. At some later point the type parameter is matched with a specific type and a complete declaration can be formed.
Among object-oriented languages generics are best known in C++, Beta, and Eiffel. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access