Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6557661

Problem with least upper bound

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      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

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                ahe Peter Ahe
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: