Type erasure
Type erasure is a technique that removes or hides concrete or generic type information from a representation or interface while preserving relevant operations or compile-time type checking.
Kotlin in Action, 2E
Type erasure is an implementation technique in which generic type arguments are removed from compiled representations and are unavailable at run time.
- How it is used
- Explains why Kotlin generic arguments cannot normally drive runtime type checks and when inline reification is needed.
- How deep it goes
- Works through is checks, star projections, unchecked casts, generated inline bytecode, and reified-function constraints.
- Examples
- Uses lists of strings and integers, printSum casts, isA<String>, and filterIsInstance<String> on a mixed list.
- What you can do after
- Diagnose/debug with it by recognizing invalid generic checks, unchecked casts, and appropriate reified runtime checks.
100 Java Mistakes and How to Avoid Them
Type erasure is Java's compilation process of removing generic type information from runtime representations while preserving compile-time generic checks.
- How it is used
- Explains why unchecked generic casts can surface later as ClassCastException rather than failing at the cast site.
- How deep it goes
- Traces erased type parameters to Object or bounds and compiler-inserted casts, without detailing broader bytecode generation.
- Examples
- Uses a List<String> read, an unchecked List<?>-to-List<Object> cast, and a wildcard-bounded method parameter.
- What you can do after
- Diagnose/debug delayed ClassCastException by tracing earlier unchecked generic casts and replacing them with wildcard or wrapper-based designs.
Read how 100 Java Mistakes and How to Avoid Them explains type erasure →
Also covered in
What to know first
- genericsGenerics are programming-language constructs parameterized by types, allowing definitions to apply to multiple concrete types while preserving type relationships.
- DebugDebug is a Rust standard-library formatting trait for producing programmer-oriented representations of values.
Related concepts
- trait objectequivalent to · A Rust trait object is a value accessed through a trait interface with its concrete implementing type hidden and methods dispatched dynamically.
- genericscontrasts with · Generics are programming-language constructs parameterized by types, allowing definitions to apply to multiple concrete types while preserving type relationships.
- ParameterizedTypeReferenceaddressed by · ParameterizedTypeReference is a Spring type token that preserves generic type information for runtime type resolution.
- reified type parametercontrasts with · A reified type parameter is an inline-function type parameter whose actual type information is available at runtime for restricted operations such as type checks and casts.
- Boxuses · Box is a Rust owning smart pointer that provides indirection by storing a uniquely owned value in heap-allocated memory.
Questions about type erasure
What is type erasure?
Type erasure is a technique that removes or hides concrete or generic type information from a representation or interface while preserving relevant operations or compile-time type checking.
Which Manning books explain type erasure?
Kotlin in Action, 2E and 100 Java Mistakes and How to Avoid Them.
What should I know before learning type erasure?
Manning books that teach type erasure usually introduce generics and Debug first.
What is the difference between type erasure and generics?
Type erasure is a technique that removes or hides concrete or generic type information from a representation or interface while preserving relevant operations or compile-time type checking. Generics are programming-language constructs parameterized by types, allowing definitions to apply to multiple concrete types while preserving type relationships.
What kinds of type erasure are there?
Kinds of type erasure include generic type erasure.
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.

