From reading the K&B
SCJP 5.0 cert book, the wildcard syntax is used to declare that a method can take a list of a generic type and its subtypes or supertypes, but it signifies that the list will not be modified. For instance,
is legal as long as inspectList() is not modifying the list. I think my statement is backed up by the summary in K&B on page 610 where it states that, "When using a wildcard, List<? extends Dog>, the collection can be accessed but not modified."
However, I am confused when I am looking at the Collections API. For instance, it declares reverse() located at:
Class Collections,
reverse
public static void reverse(List<?> list)
Reverses the order of the elements in the specified list.
So, my confusion lies in the fact that this static method is not returning a new list. So, in order for it to reverse, isn't it modifying the original list? In other words, is it more accurate to say that the wildcard prevents adding and removing from a list? Or is reverse() modifying the iterator that would be returned so that it will iterate over the reverse order thus leaving the original list alone and unmodified?
Regards,
Dan
p.s. it was a pain in the butt to change all the (, <, ), and >. This makes it real difficult to post a question about generics. I felt like giving up =( as I revisited my post 7 times to find the bad syntax.