What is the main benefit of using generics in Java collections?
Correct answer C. Type errors are caught at compile time and casts are avoided
Explanation
With a declaration such as List, the compiler rejects insertion of the wrong type and inserts casts for you on retrieval. Errors surface when compiling instead of as a ClassCastException later. Generics do not remove boxing or shrink storage, because type information is largely erased and the same bytecode handles all type arguments.
Answer checked How we write and check questions
Discussion