Java Generics - 9. Type Erasure

This is part 9 of the 9 part series on Java Generics Prev Topic Target Types Topics 1. Introduction 2. Bounding 3. Multiple bounding 4. Generic Methods 5. Wildcards 6. Typed Classes as method parameters 7. Upper and Lower Bounds 8. Target Types 9. Type Erasure Java Generics - Type Erasure Java Generics were created for tight type checking during compile time. Java complier applies the type erasure to the java code. Actually it replaces generic types by: Bounds for bounded types and Object for all unbounded types Inserts casting where necessary Add bridge methods whenever needed The Generics also ensures that no new classes are created by the compiler to achieve these goals. Have a look at the types class called Gen<E> below that is unbounded. It is in fact compiled as the class Gen with th...