liveBook · Manning

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.

How 2 Manning books explain it

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.

Read how Kotlin in Action, 2E explains type erasure →

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

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.