I mostly get the new variance ideas, but I've come across a case that won't compile and I don't understand why:
// Array test
Object[=] array1 = new Object[5];
Integer[=] array2 = new Integer[5];
array1 [0] = new Integer(1);
array2 [0] = new Integer(2);
Integer[-] array3;
array3 = array1;
array3 = array2;
array3 [0] = new Integer(3);
// This is the List equivalent?
List<=Object> list1 = new ArrayList<Object>();
List<=Integer> list2 = new ArrayList<Integer>();
list1.add (new Integer(1));
list2.add (new Integer(2));
List<-Integer> list3;
list3 = list1;
list3 = list2;
list3.add (new Integer (3));
The first half (dealing with arrays) all compiles fine. However, I get a compile error on the very last line:
Reference to add is ambiguous, both method add(E) in java.util.Collection<=-java.lang.Integer> and method add(E) in java.util.List<-java.lang.Integer> match
I don't understand this - is it a bug in the supplied libraries or do not I not understand contravariance properly?