0

When I read about generic programming, often, are used this two terms:

  1. parametrized types;
  2. type parameters

Are there difference between them?

xdevel2000
  • 20,780
  • 41
  • 129
  • 196

3 Answers3

5

In Java, in the following declaration

public class Foo<T> { ... }

Foo is a parameterized type. T is a type parameter.

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
  • Is also an instance creation (i.e. Foo f = new Foo<>();) a parametrized type? – xdevel2000 Nov 15 '13 at 10:15
  • @xdevel2000 Generics in Java are a compile time concept (think of type erasure). When we speak of types, we mean array, class, interface, or enum types. So an instance is not a type of any sort. In your comment's code snippet, the `` part is a type _argument_, `Foo` is a _parameterized type_. – Sotirios Delimanolis Nov 15 '13 at 13:31
3

Using C++ terminology:

A class template corresponds to a parameterised type - it becomes a type once you specify arguments for the parameters.

A type parameter is a parameter of a template, for which the arguments are types.

Angew is no longer proud of SO
  • 167,307
  • 17
  • 350
  • 455
2

Generic types are also known as parametized types.

Type parameters refers to the types associated with a generic type. For example, with

Dictionary<T1, T2>

T1 and T2 are the type parameters.

David Arno
  • 42,717
  • 16
  • 86
  • 131