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

Misleading report with type variables when extending one of the type arguments

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      javac reports a misleading error when compiling the attached source code. Specifically, the first error message should not be reported.

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

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Only the second error message should be reported.
      ACTUAL -
      Foo.java:4: error: type argument T1#1 is not within bounds of type-variable T1#2
          Foo<T1, T1> x;
              ^
        where T1#1,T1#2 are type-variables:
          T1#1 extends Object declared in class Bar
          T1#2 extends Object declared in class Foo
      Foo.java:4: error: type argument T1 is not within bounds of type-variable T2
          Foo<T1, T1> x;
                  ^
        where T1,T2 are type-variables:
          T1 extends Object declared in class Bar
          T2 extends Number declared in class Foo
      2 errors

      ---------- BEGIN SOURCE ----------
      class Foo<T1, T2 extends Number> {}

      class Bar<T1, T2> {
          Foo<T1, T1> x;
      }

      ---------- END SOURCE ----------

      FREQUENCY : always


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

              Created:
              Updated: