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

Compile-time error when using wildcard as type argument

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      A DESCRIPTION OF THE PROBLEM :
      In the attached program, the compiler reports the following error (see Actual Result).
      If we remove `? extends` from `? extends ClsA<Integer>` the program compiles.
      Hence, `ClsA<Integer>` <: `ClsA<? super X>` when X equals `? extends Integer`.
      Since `? extends ClsA<Integer>` <: `ClsA<Integer>`, I would expect the program to compile.
      successfully.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      javac ClsA.java

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Compile
      ACTUAL -
      ClsA.java:15: error: type argument ? extends ClsA<Integer> is not within bounds of type-variable Y
        public final void foo(ClsB<? extends Integer, ? extends ClsA<Integer>> bar) {}
                                                      ^
        where Y,X are type-variables:
          Y extends ClsA<? super X> declared in class ClsB
          X extends Object declared in class ClsB
      1 error

      ---------- BEGIN SOURCE ----------
      abstract class ClsA<M> {
        public ClsA() {}
      }

      class ClsB<X, Y extends ClsA<? super X>> {
        public ClsB() {
          super();
        }
      }

      class ClsC {
        public ClsC() {
          super();
        }
        public final void foo(ClsB<? extends Integer, ? extends ClsA<Integer>> bar) {}
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


        Attachments

          Activity

            People

            Assignee:
            vromero Vicente Arturo Romero Zaldivar
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: