What is the concept of removing generic type information at runtime called?

The story behind the answer

The concept of removing generic type information at runtime is called type erasure.

Java generics were designed with backward compatibility in mind. Rather than requiring a new generic-aware JVM, the Java compiler erases most type parameters after checking the source code. For example, a List<String> is represented broadly like a List at runtime, while the compiler inserts casts where values are read back.

This approach lets generic code interoperate with older Java libraries that use raw types. It also explains why code cannot normally use expressions such as instanceof List<String>: the parameterized type is not fully available to the JVM. The runtime can generally distinguish List from another class, but not the type argument String from Integer.

Type erasure does not mean Java performs no type checking. The compiler checks assignments and method calls before erasure, and an automatically inserted cast can still fail later with ClassCastException if unsafe raw-type code has polluted a collection. Type reflection, casting, and inference are related concepts, but none names this compile-time transformation.

Source: Wikipedia · fact-checked Aug. 2026

Add question to a list

Choose a list to keep this question in: