JavaAdvanced#generics

What is type erasure in Java generics?

The compiler removes generic type information after compile-time checks and replaces type parameters with their bounds (or Object), so generic type info isn't available at runtime via reflection on the raw type.

Example
List<String> l1 = new ArrayList<>();
List<Integer> l2 = new ArrayList<>();
l1.getClass() == l2.getClass(); // true, both are just ArrayList at runtime

Related Questions

1
JavaIntermediate#collections

How do you sort a List of custom objects by multiple fields?

Open
2
JavaBeginner#generics

What is the diamond operator in generics?

Open
3
JavaBeginner#exceptions

What is the exception hierarchy in Java?

Open