Skip to content
Latchkey

What Is Type Erasure?

Type erasure is a technique where the concrete type arguments of generic code are removed and replaced by a shared representation, such as a common base type or a boxed value. A single compiled version then handles all type arguments through that uniform interface. It keeps code size small at the cost of runtime dispatch or boxing.

Why it matters

Erasure produces one copy of generic code regardless of how many types use it, keeping binaries and compile times smaller than monomorphization. The downside is indirection and the loss of some type information at runtime.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →