DELAPARRA
Index
Color
NL
Category: Programming paradigms

Type Parameter

Explained by Updated

What is Type Parameter?

Type Parameter: A placeholder type, conventionally T, filled in when the generic is used, e.g. Array, Box. A type parameter is a placeholder for a type in generic code, usually written T. Collection<T> means a collection of some type that is chosen when you use it, so Collection<User> holds users and Collection<Order> holds orders.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about Type Parameter

How is Type Parameter used in practice?

The code is written once, and the compiler or static analyser checks each use with the actual type filled in. Methods like first() then know they return a User or an Order, not just "something".

What should you keep in mind with Type Parameter?

In TypeScript, Java and C#, type parameters are part of the language. In PHP, you write them in docblocks with @template T, and PHPStan or Psalm check them. Laravel's own code is annotated this way, which is why your editor knows what an Eloquent query returns. Constraints like T extends Model limit which types are allowed.

At a glance

CategoryProgramming paradigms
Explained by
Updated

More Programming paradigms terms

All terms starting with T

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.