The Generics used to deal with compile type-safe object & avoid the chances of ClassCasteException. The Generics make code stable by detecting bugs/errors at compile time.
Normally you can store any type of object in collections i.e., generic or non-generic. The Generics facilitated the programmer to store a specific type of object.
Compile type safety
You can hold a single type of object and it doesn’t allow you to store another object.
The Compile-time checking is checked at compile time so none of any problem occurs at runtime. A good coding strategy says it is far better to handle problems at compile time than runtime.
/*Generics collection syntax */ ClassOrInterface<Type> /*Example */ Arraylist<String>
Typecasting is not required because there is no need to do typecast the object.