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


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


      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.


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

          Issue Links



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


                • Created: