Java Interview Question

Use this basic question and answer to prepare for your next Java interview.

What are Generics in Java?


Generics are a feature that allow a class to be parameterized into sub-types. Generics provide compile-time safety and prevent runtime typecasting errors resulting in ClassCastException. Without generics, a user is forced to use the lowest common base-class and then typecast the object, which is highly error-prone and has no type-safety.

Looking for developers?