One of these assignments should fail:
import java.util.*;
public class X {
<T> Map<T,T> foo(T t1, T t2, T t3) {
return null;
}
<U extends Object, V extends U> void bar(U u, V v, List<? extends V> lv) {
Map<Object,Object> map1 = foo(u, v, lv.get(0));
Map<U,U> map2 = foo(u, v, lv.get(0));
}
}
X.java:9: incompatible types
found : java.util.Map<java.lang.Object,java.lang.Object>
required: java.util.Map<U,U>
Map<U,U> map2 = foo(u, v, lv.get(0));
^
1 error
javac rejects the latter which seems incorrect. Eclipse gets it the
other way around.
Similar problem with this example:
import java.util.*;
public class X {
<T> Map<T,T> foo(T t1, T t2, T t3) {
return null;
}
<U extends Object, V extends U> void bar(U u, V v) {
Map<Object,Object> map1 = foo(u, v, null);
Map<U,U> map2 = foo(u, v, null);
}
}
X.java:9: incompatible types
found : java.util.Map<java.lang.Object,java.lang.Object>
required: java.util.Map<U,U>
Map<U,U> map2 = foo(u, v, null);
^
1 error
And:
import java.util.*;
public class X {
<T> Map<T,T> foo(T t1, T t2) {
return null;
}
<U extends Object, V extends U> void bar(U u, V v) {
Map<Object,Object> map1 = foo(u, v);
Map<U,U> map2 = foo(u, v);
}
}
X.java:9: incompatible types
found : java.util.Map<java.lang.Object,java.lang.Object>
required: java.util.Map<U,U>
Map<U,U> map2 = foo(u, v);
^
1 error