I have a couple of questions about generic wildcards in Java:
What is the difference between
List<? extends T>
andList<? super T>
?What is a bounded wildcard and what is an unbounded wildcard?
I have a couple of questions about generic wildcards in Java:
What is the difference between List<? extends T>
and List<? super T>
?
What is a bounded wildcard and what is an unbounded wildcard?
Generic wildcards are created to make methods that operate on Collection more reusable.
For example, if a method has a parameter
List<A>
, we can only giveList<A>
to this method. It is a waste for this method's funtion under some circumstances:List<A>
, then we should be allowed to giveList<A-sub>
to this method. (Because A-sub IS a A)List<A>
, then we should be allowed to giveList<A-super>
to this method. (Because A IS a A-super)