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

Type inference fails to detect target type conflict

XMLWordPrintable

    • generic
    • generic

      Certain method invocations involving type inference pass the compiler, even though the equivalent without inference is clearly illegal. Key elements seem to be a wildcard with an interface lower bound and an assignment to a target type.

      interface A { boolean isBlue(); }

      <T> T makeT(Iterable<? super T> l) { return null; }
      String makeStr(Iterable<? super String> l) { return null; }

      {
      Iterable<? super A> la = null;
      Iterable<? super Number> ln = null;
      Iterable<? super Cloneable> lc = null;

      String s1 = makeT(la); // no error!
      String s2 = makeT(ln); // error
      String s3 = makeT(lc); // no error!
      String s4 = makeStr(la); // error
      String s5 = makeStr(ln); // error
      String s6 = makeStr(lc); // error
      }

            Unassigned Unassigned
            dlsmith Dan Smith
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: