These Go generics interview questions cover type parameters, constraints, comparable, type sets, type inference, generic types and design limits. We gathered them from public interview lists, coding rounds and community threads. Then we rewrote them in plain words and grouped them by idea.
This post is questions only, so answer each one in your own words first. When you need help, read Go generics explained with examples and Go in-memory cache with generics. Also, finish Part 8 on interfaces first, because every constraint in Go is an interface.
How to Use These Go Generics Interview Questions
Answer each of these Go generics interview questions out loud, then write a tiny program to prove your answer. Generics errors come from the compiler, so the fastest way to learn is to try and read the message. Finally, try the scenario questions, since they test judgement more than syntax.
The table below lists each section and its number of questions.
| Section | What it tests | Questions |
|---|---|---|
| Generics basics | Why generics and type parameters | 15 |
| Constraints | any, comparable, unions and ~T | 16 |
| Type inference | When Go can guess the type | 14 |
| Generic types | Generic structs, methods and aliases | 15 |
| Design and limits | When not to use generics | 16 |
| Generic coding tasks | Classic interview programs | 14 |

Go Generics Interview Questions on the Basics
Before you answer, study Go generics explained with examples. These Go generics interview questions check the syntax and the reason generics exist at all.
- What are generics, and which Go version added them?
- Which problem did Go developers solve before generics, for example with interface{} or code generation?
- What is a type parameter, and where do you write it in a function?
- How do you call a generic function with an explicit type argument?
- What is instantiation, and when does it happen?
- Can a function have more than one type parameter, for example K and V?
- What is the difference between a type parameter and a regular parameter?
- Why do square brackets mark type parameters in Go?
- Which built-in helpers use generics in the standard library, such as the slices and maps packages?
- What do the min and max built-in functions accept since Go 1.21?
- How do generics improve type safety compared with any?
- Do generics make every program faster, or can they cost speed?
- When did the standard library start to ship generic packages, and why did it wait?
- Scenario: when a project has five copies of the same Contains function for different types, how would you clean it up?
- Scenario: when a teammate wants to make every function generic, what would you say in the review?
Go Generics Interview Questions on Constraints
Before you answer, study Go interfaces explained with examples. Constraints are interfaces with extra powers, so these Go generics interview questions test both ideas together.
- What is a constraint, and why does every type parameter need one?
- Which operations does the any constraint allow, and what can you not do with such a value?
- What does comparable allow, and why do maps need it for keys?
- Since Go 1.20, how can interface types satisfy comparable, and what is the risk?
- What is a union constraint such as int | float64?
- What does the tilde in ~int mean?
- Why does a constraint with ~string accept a type such as type Email string?
- What is a type set, and how does it describe a constraint?
- Why can an interface with a union only appear as a constraint?
- What does cmp.Ordered contain, and when did it arrive?
- How do you write a constraint that needs both a method and an underlying type?
- Can you use the + operator on a type parameter constrained by any, and why not?
- How do you allow a type parameter to call a String method?
- What happened to the old golang.org/x/exp/constraints package?
- Scenario: when a Sum function must work for int, float64 and your own Money type, how would you write its constraint?
- Scenario: when the compiler says T does not satisfy comparable, what would you check first?
Go Generics Interview Questions on Type Inference
Before you answer, study Go generics explained with examples again. These Go generics interview questions check when Go can guess the type for you, because that keeps call sites short.
- What is type inference, and when can you skip the type argument?
- Why can Go not infer a type parameter that only appears in the return type?
- How does inference work with untyped constants such as 3 and 4.5 together?
- What happens when you pass a named slice type to a generic function?
- How do you pass a generic function as a value, for example to another function?
- Can you assign a generic function to a variable without instantiating it?
- Why can you range over a value of type T only when every type in its type set allows it?
- Why does a zero value of T need var zero T instead of nil?
- How do you return a zero value from a generic function when the search finds nothing?
- What does the compiler do when two arguments suggest different types for T?
- How have inference rules improved in recent Go versions?
- Can you use a type parameter in a type switch, and how?
- Scenario: when a call to a generic helper needs ugly explicit types everywhere, how would you redesign the signature?
- Scenario: when a generic Find returns nil and the code does not compile, how would you fix it?
Go Generics Interview Questions on Generic Types
Before you answer, study Go in-memory cache with TTL and generics. These Go generics interview questions move from functions to types, which is where generics help the most.
- How do you declare a generic struct, for example Stack[T any]?
- How do you write a method on a generic type?
- Why can a method not declare its own extra type parameters?
- How do you work around the missing generic methods with a top level function?
- Can a generic type satisfy an interface, and how?
- How do you create a generic linked list node that points to the next node?
- What is the difference between Stack[int] and Stack[string] at run time?
- Can a generic type embed a type parameter, and why not?
- How do generic type aliases work since Go 1.24?
- Can you build a generic Set type on top of a map, and how?
- How do generic types help with a typed cache or a typed pool?
- How do iterators with iter.Seq use generics in Go 1.23 and later?
- Should a generic type expose its fields or keep them private?
- Scenario: when a cache must store users in one place and orders in another, how would you write one generic type for both?
- Scenario: when you need a method that converts Stack[T] into Stack[U], how would you handle the language limit?
Generics Design and Limits
Before you answer, think about real code reviews you have seen. These Go generics interview questions test judgement, so explain the trade-off behind each answer.
- When should you prefer an interface over a generic function?
- What is the rule of thumb about writing code first and adding generics later?
- How does Go compile generic code, for example with GC shape stenciling and dictionaries?
- Why can a generic function that calls methods through an interface constraint be slower?
- How do generics affect binary size and compile time?
- How do generics affect readability for new team members?
- When is reflection still needed even with generics?
- Why do many libraries keep non-generic APIs for backward compatibility?
- How do you document a generic function so that callers understand the constraint?
- How do you test a generic function, and with how many types?
- What features are still missing from Go generics, for example specialization?
- Should a public API return a generic type, and what are the risks?
- How do generics change the way you write data structures for interviews?
- Can generics replace code generation tools in every case?
- Scenario: when a benchmark shows a generic version is slower than the plain version, what would you do?
- Scenario: when a pull request adds a generic Repository[T] for every table, how would you judge it?
Go Generics Interview Questions for Coding Rounds
Before you answer, write each function by hand and run it with two types. Interviewers watch your constraint choices, not only whether the code runs.
- Create a generic Map function that turns []T into []U.
- Write Filter and Reduce functions for any slice.
- Implement a Contains function with the comparable constraint.
- Write a Max function with cmp.Ordered.
- Build a generic Stack with Push, Pop and Len.
- Build a generic Queue that uses a slice inside.
- Write a Keys function that returns the keys of any map.
- Create a generic Set with Add, Has and Remove.
- Define a generic Pair type with First and Second fields.
- Write a Sum function for int, float64 and their named types.
- Make a generic cache with a mutex and a time to live.
- Write a GroupBy function that groups a slice by a key function.
- Scenario: when an interviewer asks for a binary search that works for ints and strings, how would you write the signature?
- Scenario: when a generic helper must return an error for an empty slice, how would you return its zero value?
Code Reading Questions
Read each program carefully and predict the output before you run it. Then explain the result in your own words.
package main
import (
"cmp"
"fmt"
)
func Max[T cmp.Ordered](items ...T) T {
var best T
for i, v := range items {
if i == 0 || v > best {
best = v
}
}
return best
}
type Celsius float64
func main() {
fmt.Println(Max(3, 9, 4))
fmt.Println(Max("pear", "apple", "plum"))
fmt.Println(Max[float64](2, 7.5))
fmt.Println(Max(Celsius(21.5), Celsius(19)))
fmt.Println(Max[int]())
}
- What does each line print, and why does Celsius satisfy cmp.Ordered?
- Why does the last call need an explicit type argument, and what does it return?
The second program uses a generic type and a function with two type parameters.
package main
import "fmt"
type Stack[T any] struct {
items []T
}
func (s *Stack[T]) Push(v T) { s.items = append(s.items, v) }
func (s *Stack[T]) Pop() (T, bool) {
var zero T
if len(s.items) == 0 {
return zero, false
}
v := s.items[len(s.items)-1]
s.items = s.items[:len(s.items)-1]
return v, true
}
func Map[T, U any](in []T, f func(T) U) []U {
out := make([]U, 0, len(in))
for _, v := range in {
out = append(out, f(v))
}
return out
}
func main() {
var s Stack[string]
s.Push("go")
s.Push("rust")
v, ok := s.Pop()
fmt.Println(v, ok)
s.Pop()
v, ok = s.Pop()
fmt.Printf("%q %v\n", v, ok)
lens := Map([]string{"a", "bb", "ccc"}, func(s string) int { return len(s) })
fmt.Println(lens)
}
- What does each print line show, and what value does Pop return when the stack is empty?
- How does Go infer both T and U in the call to Map?
Quick Revision Table for Go Generics
Use the table below as a final check before your interview. It lists the constraints you will meet most often.
| Constraint | What it allows | Example use |
|---|---|---|
| any | Any type, no operators | Stack[T], Map |
| comparable | == and != | Map keys, Contains |
| cmp.Ordered | < > <= >= and == | Max, Sort, binary search |
| ~int or ~string | Types with that underlying type | Named types like Email |
| int or float64 union | Only the listed types | Sum of numbers |
| Method in interface | Calling that method | T with a String method |
Also, many interviewers ask you to compare generics and interfaces directly. The diagram below shows the difference side by side.

Official Resources
These official pages explain the rules behind these questions.
- Go blog: An Introduction To Generics
- Tutorial: Getting started with generics
- Go blog: When To Use Generics
- Go specification: Type parameter declarations
Quick Recap
- These Go generics interview questions cover basics, constraints, inference, generic types, design and coding tasks.
- A type parameter lives in square brackets, and its constraint is an interface.
- Use comparable for map keys and cmp.Ordered for sorting and comparing.
- The tilde in ~T matches every type with that underlying type.
- Methods cannot add their own type parameters, so use top level functions instead.
- Start with plain code, then add generics when you repeat the same logic for many types.
What’s Next?
By now, you have Go generics interview questions for every part of type parameters and constraints. Study the answers in your own notes, then check them against the Go interview topics study guide.


