Generics
Writing a type or function once so it works with many types, while keeping type safety.
Definition
Generics let you write code with a placeholder type, like Array<Element> or List<T>, that is filled in when the code is used. You get one implementation that works for strings, users or orders, and the compiler still stops you from mixing them up.
In practice
A Cache<Key, Value> class can store images by URL in one place and users by ID in another, with no casts.
Learn it in context
Lessons that use this term.