This is Collections copy method(part of it) :
public static <T> void copy(List<? super T> dst, List<? extends T> src) {
for (int i = 0; i < src.size(); i++) {
dst.set(i, src.get(i));
}
}
There are 4 sample call :
List<Object> objs = Arrays.<Object>asList(2, 3.14, "four");
List<Integer> ints = Arrays.asList(5, 6);
1. Collections.copy(objs, ints);
2. Collections.<Object>copy(objs, ints);
3. Collections.<Number>copy(objs, ints);
4. Collections.<Integer>copy(objs, ints);
How above call works ?
We could also declare the method with several possible signatures
1. public static <T> void copy(List<T> dst, List<T> src)
2. public static <T> void copy(List<T> dst, List<? extends T> src)
3. public static <T> void copy(List<? super T> dst, List<T> src)
4. public static <T> void copy(List<? super T> dst, List<? extends T> src)
For the example calls above,
the first of these is too restrictive, as it only permits calls when the destination and source have exactly the same type. (Understood).
the second signature works only when the type parameter is Object
the third signature works only when the type parameter is Integer
the last signature works for all three type parameters—i.e., Object, Number, and Integer.
Please explain the second, third and last signatures too ?
The remaining three are equivalent for calls that use implicit type parameters, but differ for explicit type parameters.
What does this above statement means ?