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

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

Mastering Java: The Ultimate Quiz for 'Thinking in Java'. Dive deep into Java with multiple-choice questions. Challenge yourself with quiz questions designed to test and improve your understanding of the 'Thinking in Java' book. Get ready for your exam!

Practice this question and more.


Why might you use List<? extends Object> instead of List<?>?

  1. To clarify that objects in the List extend Object

  2. To allow addition of any object type to the List

  3. There is no practical use; they mean the same thing

  4. To differentiate from raw types in method signatures

The correct answer is: There is no practical use; they mean the same thing

List<?> and List<? extends Object> essentially have the same meaning, as both are wildcard types that can store any type of objects. Therefore, there is no practical difference in using one over the other. Option A is incorrect because the keyword "extends" is not necessary when using the wildcard "?". Option B is incorrect as both options allow for the addition of any object type to the list. Option D is incorrect because the usage of wildcard types is not related to differentiating from raw types in method signatures.