public static void main(String[] args) {
List extends Object> mylist = new ArrayList
List extends Object>
, which is the same as List>
, fulfills the purpose of generalizing all types List
, List
, List
, etc. (so all types with a proper type in place of the ?
). Values of all of these types can be assigned to a variable of type List>
(which is where it differs from List
!).
In general, you cannot add a string to such a list. However, you can read Object
from the list and you can add null
to it. You can also calculate the length of the list, etc. These are operations that are guaranteed to work for each of these types.
For a good introduction to wildcards, see the paper Adding Wildcards to the Java Programming Language. It is an academic paper, but still very accessible.