Generics
Generics are programming-language constructs parameterized by types, allowing definitions to apply to multiple concrete types while preserving type relationships.
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
- Uses generics to replace duplicated Go collection logic while preserving type relationships at compile time.
- How deep it goes
- Works through generic functions, interfaces, linked lists, maps, constraints, compiler performance, and language limitations.
- Examples
- Demonstrates recipe filtering, a linked list, a two-parameter map, and domain sorting with slices.SortFunc.
- What you can do after
- Build generic Go functions and collections, choose constraints, and evaluate when simpler abstractions are preferable.
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
- Enables reusable, type-safe Go functions and types without repeating implementations for each data type.
- How deep it goes
- Explains type parameters, constraints and inference through function and cache declarations.
- Examples
- Uses a pretty-print function and a key-value cache with comparable keys and arbitrary values.
- What you can do after
- Build a generic key-value cache from scratch using constrained key and value types.
Read how Learn Go with Pocket-Sized Projects 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 parametric methods and types to relate argument and field types while reducing repeated definitions.
- How deep it goes
- Works through signatures, bounds, constructors, and geometric operations, then explains performance through boxing and memory layout.
- Examples
- Uses linear search, a typeof-style function, and two-dimensional point and vector operations.
- What you can do after
- Builds parametric methods and types from scratch to relate arguments, constrain fields, and reuse implementations.
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
- Uses generic functions to reuse code across concrete types while specifying required capabilities.
- How deep it goes
- Explains parameter declarations, trait bounds, compiler errors and compile-time concrete functions, then compares named generics with impl Trait.
- Examples
- Uses return_item, debug printing, a two-type comparison and iterator method signatures to illustrate generic parameters.
- What you can do after
- Builds generic functions with named type parameters and trait bounds, including functions whose arguments share a type.
Read how Learn Rust in a Month of Lunches explains generics →
Type-Driven Development with Idris
A generic type is a type parameterized by one or more types.
- How it is used
- Uses generics to reuse data structures and operations while expressing relationships between their types.
- How deep it goes
- Defines generic types and works through constructors, constrained tree insertion, and interfaces parameterized by type constructors.
- Examples
- Uses Maybe for safe division, generic binary search trees, list append, and mapping over lists.
- What you can do after
- Build generic data types from scratch and apply interface constraints to operations on them.
Read how Type-Driven Development with Idris 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 →
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.
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.
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 reduce duplication while avoiding unnecessary abstractions in Go code.
- How deep it goes
- Works through constraints, instantiation, inference, generic types, and method restrictions, then contrasts useful and unnecessary type parameters.
- Examples
- Uses map key extraction, a linked-list node, channel merging, a sorting wrapper, and an io.Writer function.
- What you can do after
- Evaluate when Go type parameters reduce duplication and when an interface or simpler code is preferable.
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.
Acing the Frontend Interview
A generic type is a TypeScript construct that abstracts over one or more types while preserving relationships between those types.
- How it is used
- Applies generics to reusable, type-safe functions, classes, interfaces, React components, and API designs.
- How deep it goes
- Explains type variables, any comparisons, React usage, extends constraints, and keyof access, while only surveying advanced patterns.
- Examples
- Uses a generic React list, User and Animal constraints, length-based constraints, and type-safe keyof property access.
- What you can do after
- Apply generics to build reusable TypeScript components and APIs while preserving relationships and enforcing constraints.
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 →
Systems Programming with Zig
A generic is a parameterized program construct that can be instantiated for different types or values.
- How it is used
- Reuses functions across types when their bodies support the supplied values.
- How deep it goes
- Defines comptime type parameters and duck typing, then demonstrates valid numeric input and invalid boolean input.
- Examples
- Uses tokenizeScalar for text splitting and a generic sum function to contrast numeric and boolean inputs.
- What you can do after
- Apply comptime type parameters to write functions reusable across compatible types.
Also covered in
- Data-Oriented Programming in JavaIn early access (MEAP)
- Rust in Action: Systems programming concepts and techniques
- Functional Design and Architecture: Examples in Haskell
- API Design Patterns
- Go by Example
- Code Like a Pro in Rust
- Elixir in Action, Third Edition
- Python Workout, Second Edition
- Python Workout: 50 ten-minute exercises
- Akka in Action, Second Edition
- Learn Concurrent Programming with Go
What to know first
- functionA function is a callable unit of program code that performs a computation or operation, can accept inputs, and may produce a result or side effect.
- listA list is an ordered collection of elements arranged in a sequence.
- arrayAn array is an ordered collection of elements organized in one or more dimensions and accessible by position or index.
- JavaScriptJavaScript is a high-level, dynamically typed programming language standardized as ECMAScript and used for web and general-purpose programming.
Related concepts
- union typeincludes · A union type is a type whose values can represent one of several specified alternative types or variants.
- classkind of · A class is a programming-language construct that defines a type’s structure and behavior and provides a basis for creating or representing objects.
- type argumentuses · A type argument is a type supplied for a type parameter to specify or constrain the types accepted by a generic construct.
- 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.
- generic interfacepart of · A generic interface is an interface declaration parameterized by one or more type parameters, defining a contract that can be specialized for particular types.
Questions about generics
What is generics?
Generics are programming-language constructs parameterized by types, allowing definitions to apply to multiple concrete types while preserving type relationships.
Which Manning books explain generics?
Data-Oriented Programming: Reduce software complexity, Kotlin in Action, 2E, Functional Programming in Scala, Second Edition, Go in Action, Second Edition, Essential TypeScript 5, Third Edition, Learn Go with Pocket-Sized Projects, Julia as a Second Language, Idiomatic Rust and 15 more.
What should I know before learning generics?
Manning books that teach generics usually introduce function, list, array and JavaScript first.
What is the difference between generics and any type?
Generics are programming-language constructs parameterized by types, allowing definitions to apply to multiple concrete types while preserving type relationships. 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.
What kinds of generics are there?
Kinds of generics include union type.
What is generics a kind of?
Generics is a kind of class. A class is a programming-language construct that defines a type’s structure and behavior and provides a basis for creating or representing objects.
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.






















