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 →
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.
- genericsproduced by · Generics are programming-language constructs that parameterize or generalize types and operations so they can apply to multiple concrete types or input forms.
- 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.
- curryingconfigures · Currying is the transformation of a function accepting multiple arguments into a sequence of functions that accept arguments incrementally, typically one at a time.
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.

