Java Generics - Type Erasure


Generics are used for tighter type checks at compile time and to provide a generic programming. To implement generic behaviour, java compiler apply type erasure. Type erasure is a process in which compiler replaces a generic parameter with actual class or bridge method. In type erasure, compiler ensures that no extra classes are created and there is no runtime overhead.

Type Erasure rules

  • Replace type parameters in generic type with their bound if bounded type parameters are used.

  • Replace type parameters in generic type with Object if unbounded type parameters are used.

  • Insert type casts to preserve type safety.

  • Generate bridge methods to keep polymorphism in extended generic types.

Useful Video Courses


Java Date and Time Online Training

16 Lectures 2 hours

Malhar Lathkar


Java Servlet Online Training

19 Lectures 5 hours

Malhar Lathkar


JavaScript Online Training

25 Lectures 2.5 hours

Anadi Sharma


Java Online Training

Most Popular

126 Lectures 7 hours

Tushar Kale


Java Essential Training

119 Lectures 17.5 hours

Monica Mittal


Java Essentials Online Training

76 Lectures 7 hours

Arnab Chakraborty