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

Well-formed wild-carded parameterized type of Iface<T extends U, U> fails to compile

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 8
    • Fix Version/s: tbd_major
    • Component/s: tools
    • Labels:

      Description

      Following code fails to compile:

      public class Test10 {
          interface Iface<T extends U, U> { }
          public static void main(String argv[]) {
              Iface<? extends Integer, ? super Number> i = null;
          }
      }

      however according to JLS8 4.5:

      "A parameterized type C<T1,...,Tn> is well-formed if ... when subjected to capture conversion (§5.1.10) resulting in the type C<X1,...,Xn>, each type argument Xi is a subtype of S[F1:=X1,...,Fn:=Xn] for each bound type S in Bi."

      In this case, given 'CAP1 extends Integer' and 'CAP2 super Number', Iface<CAP1, CAP2> is within its bounds -- CAP1 is a subtype of CAP2.

      Swapping T and U causes compilation to succeed:

      public class Test11 {
          interface Iface2<U, T extends U > { }
          public static void main(String argv[]) {
              Iface2<? super Number, ? extends Integer> i2 = null;
          }
      }

      The code above is attached.

        Attachments

        1. Test10.java
          0.2 kB
        2. Test11.java
          0.2 kB

          Issue Links

            Activity

              People

              • Assignee:
                dlsmith Dan Smith
                Reporter:
                grakov Georgiy Rakov (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated: