Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $4.99 payment

Dive into the depths of Java with our quiz based on "Thinking in Java, Fourth Edition" by Bruce Eckel. Test your knowledge, solidify concepts, and prepare for certification with challenging questions and insightful feedback.

Practice this question and more.


How does Java handle generic types internally after type erasure?

  1. By treating them as specific, bounded types

  2. By checking their types at runtime

  3. By treating them as Object

  4. By dynamically determining the type

The correct answer is: By treating them as Object

Java handles generic types by erasing their type parameters during compilation and treating them as the non-generic type Object. This means that the generic type is essentially converted to a non-generic type and all references to its type parameters are replaced with the type Object. This is why option C is the correct answer. Option A is incorrect because Java does not treat generic types as specific, bounded types after type erasure. Instead, any type parameters or other constraints are removed. Option B is incorrect because type checks are not performed at runtime for generic types. As mentioned earlier, during compilation, all references to type parameters are replaced with the type Object. Option D is incorrect because Java does not dynamically determine the type of generic types after type erasure. Instead, it is already predetermined during compilation that the generic type will be treated as Object.