Templates For Java - Epaperpress Page 3

ADVERTISEMENT

Creating Templates
To create a template perform the following steps:
Parameterized types. Change all references from the base type to T. In the List example,
above, all references to int were changed to T.
Indicate template classes, structures, and functions. Include the following code before
each class, struct, and function that contains a parameterized type:
template<class T>
Update template references. Change all scope resolution operators that reference objects
made into templates to include the parameterized type. In the previous example all
references to List:: were replaced with List<T>::, and Node was replaced with Node<T>.
As a final note, effective with release 1.5 Java implements templates in the form of generics.

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go
Page of 3