JDK-6557661 : Problem with least upper bound
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: generic
  • CPU: generic
  • Submitted: 2007-05-15
  • Updated: 2010-04-02
  • Resolved: 2009-03-13
Related Reports
Relates :  
Relates :  
Description
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

Comments
EVALUATION Not reproducible after jdk 7 b06 (see 5042462)
13-03-2009