Generics are introduced in JDK 5 to reduce the bugs and add more abstraction over types. With generics, we can have more type-safe objects and it helps to detect bugs at compile time.

Advantages of generics

  1. Type-safety of objects
    Without generics, we can store any type of object. Generics can store only one type of object.
    When we need to store a specific type of object, it is much easier to specify the type and the compiler ensured the correctness of that types.

--

--