Generics
Generics are programming-language constructs that parameterize or generalize types and operations so they can apply to multiple concrete types or input forms.
Data-Oriented Programming: Reduce software complexity
A generic data manipulation function processes structured data according to its accessible structure rather than a specific domain class.
- How it is used
- Deploys generic data manipulation across records, database results, and web-service flows.
- How deep it goes
- Demonstrates paths, collection operations, custom updates, joins, and composition, while trading away compile-time field safety.
- Examples
- Uses catalog records, nested book titles, database rows, external book information, array joins, and duplicate-author removal.
- What you can do after
- Builds reusable data transformations and applies them to heterogeneous records without creating a class for every variation.
Read how Data-Oriented Programming: Reduce software complexity explains generics →
Kotlin in Action, 2E
A generic function is a function declared with one or more type parameters so it can operate on values of different types.
- How it is used
- Expresses reusable collection, function, class, and interface APIs while preserving element-type information at compile time.
- How deep it goes
- Explains declarations, inference, nullability bounds, erasure, runtime limits, and declaration- and use-site variance.
- Examples
- Uses collection slicing and filtering, joinToString, nullable processors, erased List checks, herds, comparators, and copyData.
- What you can do after
- Build it from scratch by declaring generic functions and classes, constraining nullability, and selecting variance for producer or consumer APIs.
Functional Programming in Scala, Second Edition
A polymorphic method is a method declared with type parameters that can operate over values of multiple types.
- How it is used
- Introduces reusable pure and higher-order functions by abstracting over the types they accept.
- How deep it goes
- Defines method type parameters, traces findFirst, and derives partial1 from its signature; later extends to polymorphic function types.
- Examples
- Uses generic array search, partial application, parameterized List construction, Free interpreters, and safe mutable-state actions.
- What you can do after
- Build it from scratch by declaring type parameters and using signatures to guide generic function implementations.
Read how Functional Programming in Scala, Second Edition explains generics →
Go in Action, Second Edition
Generic programming is a language feature that defines functions, types, and interfaces parameterized over types while preserving compile-time type safety.
- How it is used
- Reuses collection operations across types while retaining compile-time checks on values and type relationships.
- How deep it goes
- Works through generic functions, collection interfaces, linked lists, maps, constraints, and adoption trade-offs; does not benchmark a production workload.
- Examples
- Uses recipe filtering and title extraction, a generic linked list and hash map, and sorting recipes by serving size.
- What you can do after
- Build it from scratch: define type-safe generic collections and functions, then choose constraints and assess whether reuse warrants the abstraction.
Essential TypeScript 5, Third Edition
A generic type is a parameterized type containing placeholders that are resolved for a particular use or object creation.
- How it is used
- Keeps reusable collections and operations type-safe when they handle different item types.
- How deep it goes
- Works through parameters, arguments, constraints, inheritance, interfaces, runtime guarding, and advanced collection types.
- Examples
- Uses to-do items in a Map and collections of people, products, and cities, including a failed `instanceof` check.
- What you can do after
- Build it from scratch: define a constrained generic collection and choose type arguments for each instance.
Read how Essential TypeScript 5, Third Edition explains generics →
Learn Go with Pocket-Sized Projects
A parameterized type is a type declaration that includes type parameters and can be instantiated with concrete types.
- How it is used
- Uses generics to make a reusable, type-safe key-value cache instead of repeating implementations for different key and value types.
- How deep it goes
- Works through type parameters, inference, constraints, and a parameterized cache; treats concurrency safety as a separate implementation requirement.
- Examples
- Shows a parameterized printing function, a generic slice type, and a cache with comparable keys and unrestricted values.
- What you can do after
- Build it from scratch: declare a parameterized Go cache with appropriate constraints, an initializing constructor, and key-value methods.
Read how Learn Go with Pocket-Sized Projects explains generics →
Idiomatic Rust
A generic function is a function defined with type or value parameters so it can operate across multiple parameterizations.
- How it is used
- Enables type-safe reuse of functions and data structures across types without repeating definitions.
- How deep it goes
- Works through parameter syntax, inference failures, explicit annotations, and trait bounds, while noting compile-time and readability costs.
- Examples
- Uses an ambiguous `Container<Option<String>>`, a bounded description function, and tagged structs to expose compiler requirements.
- What you can do after
- Build it from scratch: define reusable Rust types and functions, add necessary bounds, and resolve ambiguous type inference.
Write Powerful Rust Macros
A generic function is a function parameterized by types or other compile-time parameters.
- How it is used
- Uses generic functions to reduce duplication while preserving the readability of ordinary function-based code.
- How deep it goes
- Compares generic functions with macros and illustrates generic implementation blocks through a blanket implementation.
- Examples
- Demonstrates a Hello trait implemented for every Copy type, enabling numbers, characters, and Booleans to call hello.
- What you can do after
- Evaluate when generic functions or blanket implementations provide a clearer alternative to macros.
Go in Practice, Second Edition
A generic function is a function declared with type parameters so it can operate across multiple permitted concrete types.
- How it is used
- Uses generic functions to share slice-processing logic across element types without duplicating implementations.
- How deep it goes
- Works through generic structs, function type parameters, inference, and constrained filters without descending into compiler internals.
- Examples
- Demonstrates filtering capitalized strings and divisible-by-three integers, then retaining positive `int8` and `float32` values.
- What you can do after
- Build it from scratch: implement a reusable slice filter or restrict a numeric filter to permitted types.
Learn Rust in a Month of Lunches
A generic function is a Rust function parameterized by one or more type parameters and usable with multiple concrete types.
- How it is used
- Reuses functions across concrete input types without repeating their definitions.
- How deep it goes
- Works through type-parameter syntax, compiler errors, trait bounds, multiple parameters, and the distinction from `impl Trait`.
- Examples
- Uses an item-returning function, `Debug` formatting feedback, a two-value comparison, and closure-taking iterator signatures.
- What you can do after
- Build it from scratch: write functions that accept multiple concrete types while requiring the traits their operations need.
Read how Learn Rust in a Month of Lunches explains generics →
Fabulous Adventures in Data Structures and Algorithms
A generic type is a parameterized type whose definition can operate over one or more type parameters.
- How it is used
- Uses generic types to enforce recursive data-structure shapes, abstract over graph nodes, and add capabilities to values.
- How deep it goes
- Works through nested deque types and monadic wrappers, but names monad laws without developing them.
- Examples
- Shows a recursively typed deque, an immutable graph wrapper, Unit factories, and a generic-method inference problem.
- What you can do after
- Build it from scratch: define type-safe immutable structures with recursive generic types or generic node parameters.
Read how Fabulous Adventures in Data Structures and Algorithms explains generics →
Julia as a Second Language
A parametric method is a method whose signature includes type parameters that constrain or relate its argument types.
- How it is used
- Uses type parameters to reuse methods while specifying relationships between argument types.
- How deep it goes
- Works through `where` clauses, matching and differing parameters, and subtype constraints; does not develop compiler internals for parametric methods.
- Examples
- Tests a linear search, implements a typeof-style function, and defines operations on parameterized points and vectors.
- What you can do after
- Build it from scratch: write parametric Julia methods that reuse code and enforce intended argument-type relationships.
React in Depth
A generic function is a function declared with type parameters whose parameter and return types can vary for each invocation.
- How it is used
- Preserves relationships between input and output types in reusable functions, then applies the same technique to React components with varying item types.
- How deep it goes
- Works through a typed middle-element function, inference and explicit type arguments, then develops a generic pagination component and notes wrapper limitations.
- Examples
- Uses a middle-element array function and a four-items-per-page component rendering employee cards or high-score entries.
- What you can do after
- Build it from scratch: type a reusable function or pagination component so each invocation keeps its inputs and outputs consistent.
Learn Haskell by Example
A function that can operate with values of more than one type through generalized type behavior.
- How it is used
- Builds reusable higher-order functions and parameterized data types without fixing their value types.
- How deep it goes
- Explains type-variable substitution and inference through function and Maybe examples, while deferring constraints to type classes.
- Examples
- Uses transform from lists to lists, an Int-to-String function, and fromMaybe over Maybe values.
- What you can do after
- Apply it by reading and writing signatures whose repeated type variables enforce consistent types across inputs and results.
100 Go Mistakes and How to Avoid Them
A programming-language feature that allows code and types to be parameterized over type parameters.
- How it is used
- Uses generics to replace duplicated map-key extraction and judge when type-parameter abstraction improves Go code.
- How deep it goes
- Explains compile-time instantiation, constraints, generic types, and method limitations; leaves channel merging as a function signature.
- Examples
- Contrasts type-switched and generic map-key extraction, then sorts a slice through a parameterized comparison wrapper.
- What you can do after
- Build it from scratch: replace duplicated map-key extraction with a constrained generic function, and retain interfaces when only method calls matter.
Read how 100 Go Mistakes and How to Avoid Them explains generics →
.NET in Action, Second Edition
A generic type or method is parameterized by one or more types so the same definition can operate with different type arguments.
- How it is used
- Types command-line parsing so the parser can return data in the application's chosen options type.
- How deep it goes
- Defines generic arguments through method signatures and a focused parsing example.
- Examples
- Uses ParseArguments<Options> and IEnumerable<string> in command-line parsing.
- What you can do after
- Apply generics via CommandLineParser to parse arguments into a chosen options type.
Pro ASP.NET Core 7, Tenth Edition
A generic type parameter is a placeholder type specified in a generic type or method declaration and replaced by a concrete type when the generic construct is used.
- How it is used
- Builds reusable Blazor template components that render and operate on caller-supplied data objects.
- How deep it goes
- Explains declaration, typed parameters, row iteration, reuse, and optional C# where constraints.
- Examples
- Demonstrates reusable tables for Person and Department entities with typed row templates, sorting, highlighting, and related data.
- What you can do after
- Build reusable Blazor template components that accept typed sequences and render caller-provided content for each item.
Read how Pro ASP.NET Core 7, Tenth Edition explains generics →
ASP.NET Core in Action, 3e
A generic method is a method defined with type parameters that can operate on arguments or return values of specified types.
- How it is used
- Uses open generic types to register reusable dependency-injection services for many concrete type arguments.
- How deep it goes
- Explains open generic resolution and registration syntax, but stops short of implementing a generic repository.
- Examples
- Uses Repository<T>, IRepository<Customer>, DbRepository<Customer>, and an AddScoped typeof registration.
- What you can do after
- Operate/configure dependency injection by registering open generic interfaces and implementations with IServiceCollection.
100 Java Mistakes and How to Avoid Them
A generic type is a Java type declaration or use parameterized by one or more type arguments.
- How it is used
- Diagnoses collection and map bugs caused by searching or removing values whose types do not match the stored representation.
- How deep it goes
- Explains parameterized additions and unrestricted search APIs, but stops short of generic type-system internals.
- Examples
- Uses File, Path, String, List<Short>, and CharSequence-versus-Number lookup examples.
- What you can do after
- Diagnose silent lookup failures by comparing collection element representations with search and removal arguments.
Read how 100 Java Mistakes and How to Avoid Them explains generics →
F# in Action: A Revised Edition of Get Programming with F#
A generic type is a type defined with one or more type parameters so it can apply to values of different concrete types.
- How it is used
- Supports reusable F# functions and collection types that operate across concrete types without casts or type-specific wrappers.
- How deep it goes
- Explains generic types, explicit parameters, automatic generalization, inference, and resulting type errors through short examples.
- Examples
- Uses greeting functions, ResizeArray values, combineElements, explicit type arguments, omitted types, and a mismatched-type exercise.
- What you can do after
- Build reusable F# functions and collections, choose explicit or inferred type arguments, and recognize incompatible-type errors.
Read how F# in Action: A Revised Edition of Get Programming with F# explains generics →
Related concepts
- classkind of · A class is a programming-language construct that defines a type’s structure or behavior and provides a basis for creating or representing objects.
- type argumentuses · A type argument is an argument supplied to a parameterized construct to specify a type or constrain the kinds of values it accepts.
- any typecontrasts with · The any type is a TypeScript type that permits values to be treated as having essentially any type, largely disabling static type checking for them.
- TypeScriptuses · TypeScript is a statically typed superset of JavaScript that adds type-system features and is compiled to JavaScript.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.



















