The generic wildcards target two primary needs:
Reading from a generic collection
Inserting into a generic collection
There are three ways to define a collection (variable) using generic wildcards. These are:
List> listUknown = new ArrayList();
List extends A> listUknown = new ArrayList();
List super A> listUknown = new ArrayList();
List>
means a list typed to an unknown type. This could be a List
, a List
, a List
etc.
List extends A>
means a List of objects that are instances of the class A
, or subclasses of A
(e.g. B and C).
List super A>
means that the list is typed to either the A class
, or a superclass of A
.
Read more : http://tutorials.jenkov.com/java-generics/wildcards.html