Upper bounded and unlimited wildcard collections are immutable.
For example, you cannot do:
List<? extends Number> myList = new ArrayList<Integer>(); myList.add(new Integer(3));
This will not compile because java does not know what type of List List<? extends Number> List<? extends Number> is at compile time.
So, the example above at compile time myList could be List<Double> or List<Integer> or List any subclass of Number . And since you cannot add Double to the List<Integer> or vice versa, compilation failed.
Test1 test2
source share