Generics were introduced in Java 5, its main goal was to provide compile-time type-safety checks along with flexibility and reusable code.
One area where Generics played a significant role was the Collection framework. Before Generics Java Collection was used with RAW type. Using Raw type was error-prone and developers often did casting of data type, resulting in type-casting exceptions.
With Generics, developers would define the data type they need to store into the collection and any violation would be a compile-time error.
This article discusses type erasure along with code examples.
https://asyncq.com/generics-type-erasure-in-java