Generics: resources¶
Level: 201 · anyone who wants the primary sources behind this chapter
One line: The spec sections, release notes, design documents, blog posts, books and talks that settle what this chapter claims about type parameters — and three sources to read with care.
Primary sources¶
- The Go Programming Language Specification ↗ — Type parameter declarations ↗, Type constraints ↗, General interfaces ↗ (unions,
~, type sets as intersections), Satisfying a type constraint ↗ (thecomparableexception), Instantiations ↗, Type inference ↗ and Type unification ↗, Method declarations ↗. Since Go 1.25 the spec no longer uses the notion of a core type; the 1.25 release notes ↗ and the Goodbye core types ↗ post say what replaced it. - Type Parameters Proposal ↗ — Ian Lance Taylor and Robert Griesemer: the design, its omissions ↗ (no specialization, no operator methods, no variadic type parameters) and why methods may not take type arguments ↗.
- Generics implementation - GC Shape Stenciling ↗ — how the compiler instantiates: one copy of the code per GC shape (size, alignment, pointer layout), with a dictionary for what differs within a shape. This is the claim "Go is neither C++ monomorphization nor Java erasure", and it is not machine-checked in this chapter.
- Release notes: Go 1.18, Generics ↗ — the feature and the restrictions it shipped with; Go 1.20, Changes to the language ↗ — interfaces satisfy
comparable; Go 1.21, Changes to the language ↗ — inference for generic functions as arguments and in assignments, untyped constants, and thecmp,slicesandmapspackages; Go 1.24 ↗ — generic type aliases. - Packages:
cmp↗ (Ordered,Compare,Less,Or),slices↗,maps↗,iter↗ — the standard library's generic code, worth reading as models of constraints and signatures. - The Go blog: Robert Griesemer and Ian Lance Taylor, An Introduction To Generics ↗ (22 March 2022); Ian Lance Taylor, When To Use Generics ↗ (12 April 2022); Robert Griesemer, All your comparable types ↗ (17 February 2023) and Everything You Always Wanted to Know About Type Inference - And a Little Bit More ↗ (9 October 2023).
- The Go FAQ, Generics ↗ — nine entries, among them why not methods with type parameters ↗, why the receiver cannot name a specific type ↗, why inference stops where it does ↗ and how generics are implemented ↗.
- golang/go#49085 ↗ — the proposal issue to allow type parameters in methods, closed as a duplicate in April 2026; the rule stands.
Books¶
- Jon Bodner, Learning Go: An Idiomatic Approach to Real-World Go Programming, 2nd ed. (O'Reilly, 2024), chapter 8, "Generics" — "Introducing Generics in Go" (a stack, and the zero value in
Pop), "Generic Functions Abstract Algorithms", "Generics and Interfaces", "Use Type Terms to Specify Operators", "Type Inference and Generics", "Type Elements Limit Constants", "Combining Generic Functions with Generic Data Structures", "More on comparable", "Things That Are Left Out", "Idiomatic Go and Generics", "Adding Generics to the Standard Library". The most complete book treatment on the shelf, and current for Go 1.22. - Go in Practice, 2nd ed. (Manning, 2025), chapter 3, "Structs, interfaces, and generics" — section 3.4, "Simplifying code with generics", with "Using functions with generics" and "Using constraints and type approximations".
- Miki Tebeka, Effective Go Recipes: Fast Solutions to Common Tasks (Pragmatic, 2024), chapter 7, "Working with Structs, Methods, and Interfaces" — Recipe 39, "Using Generics to Reduce Code Size"; Recipe 40, "Using Generics for Type-Safe Data Structures"; Recipe 41, "Using Generics for Better Type Safety".
Not on the shelf¶
- Teiva Harsanyi, 100 Go Mistakes and How to Avoid Them (Manning, 2022) — publisher's page ↗; its mistakes on generics are about when not to use them.
- Bartłomiej Płotka, Efficient Go (O'Reilly, 2022) — the book's example repository ↗; on measuring costs, for readers of the GC-shape document who want to benchmark an instantiation.
Talks and videos¶
- GopherCon 2021: Generics! — Robert Griesemer and Ian Lance Taylor ↗ — the design as it shipped in 1.18, from its authors.
- Go Day 2021 on Google Open Source Live: Using Generics in Go — Ian Lance Taylor ↗ — the guidelines that became When To Use Generics.
- GopherCon 2019: Generics in Go — Ian Lance Taylor ↗ — the contracts draft; watch it for the reasoning, not the syntax, which changed before 1.18.
Read with care¶
- Alan A. A. Donovan and Brian W. Kernighan, The Go Programming Language (Addison-Wesley, 2015) — written for Go 1.5, seven years before type parameters: its
sort.Interfaceandinterface{}idioms are how the same problems were solved without generics, and its chapter 7, "Interfaces", is still the best account of what a basic interface is. Nothing in it is wrong; nothing in it mentions[T any]. - Adam Freeman, Pro Go (Apress, 2022) — covers Go 1.17 and has no generics at all, so its container and "any value" chapters solve with
interface{}what this chapter solves with type parameters. - The pre-1.18 design drafts — contracts (2018–2019), and code written against
golang.org/x/exp/constraints:constraints.Orderedbecamecmp.Ordered↗ in Go 1.21, and the rest of that package (Integer,Float,Signed) never moved into the standard library. - Anything that says an interface type cannot be a
comparabletype argument — true until Go 1.19, false since 1.20 (Constraints are type sets). - Anything that says
slices.SortFunc(xs, cmp.Compare[string])needs the explicit instantiation — true until Go 1.20, unnecessary since 1.21 (Inference works from arguments, not results).
Checked 2026-09-23.