Originally posted by Joyce Lee:
Some examples of wildcard type parameter used on non-generic method can be seen in Collection interface like addAll, containsAll, removeAll and retainAll and its subclasses.
Thanks for the response!
First let me verify some terminology: When you say "non-generic method," you're talking about a method that does not specify its own type parameter, but still might take arguments of a generic type. For example, public void meth1(List<Integer> inList){} would be non-generic, as opposed to the obviously generic, public <T> void meth2(T t){}. Correct?
My impression from reading Schildt (referenced
here) is that
both would be considered "generic methods." If this isn't accurate, then the way I phrased my question would have been misleading.
What I'm really asking is this: Are there any valid uses of the wildcard
outside of a method's argument list? For example, would it ever make sense to do the following (which, as you point out above, opens the door for some interesting compilation errors)?
List<?> myList = new ArrayList<Integer>();
[ March 03, 2005: Message edited by: marc weber ]