In computer programming, when you declare something using brackets, what is it called?

In computer programming, when you declare something using  brackets, what is it called? by John L. Miller

Answer by John L. Miller:

It all depends upon the language. The example you give above is called a template. It’s a way of taking a generic data structure / class definition, and specializing it for a data type.

For example, without templates we used to have to create a special list for each data type. An IntList class for integers, a FloatList class for lists of floating point numbers, and so on. If you were clever, you created a List class, and created subclasses for each new type you needed, e.g. IntList : List and FloatList : List, but it was still the same problem.

With templates, you can specify a type to be used internally in the definition. When you create an instance of a template specialized e.g. to int, then everywhere that type parameter (named ‘T’ by convention) is used gets automatically declared as the type you specified in the angle brackets.

public class MyList<T> {
    T [] m_items;
	T GetItem(int n) {return m_items[n];}
    ... 
} 

MyList<int> intList; 

In computer programming, when you declare something using <> brackets, what is it called?

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s