Disable ads (and more) with a membership for a one time $4.99 payment
Why are wrapper classes used in Java generics?
To allow primitive types as type parameters
For type safety and elimination of casts
To enhance performance
To enable collections to work with primitives
The correct answer is: To allow primitive types as type parameters
Wrapper classes are used in Java generics to allow primitive types as type parameters. This is because generics only accept objects as type parameters, so primitive types cannot be used directly. Wrapper classes, such as Integer and Double, wrap around the primitive types and allow them to be used in generics. Additionally, using primitive types in generics would result in auto-boxing and unboxing, which can cause performance issues. Therefore, options B, C, and D are incorrect as they either do not mention the main purpose of wrapper classes in generics or they suggest incorrect reasons for using them.