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

4.5: When are wildcards "the same"?

XMLWordPrintable

    • generic
    • generic

      The following shows that javac is inconsistent in determining
      which overriders are allowed:

      class Box<T extends Number> {}

      class T1 { // works
          static class A {
              void f(Box<?> box) {}
          }
          static class B extends A {
              void f(Box<? extends Object> box) {}
          }
      }

      class T2 { // works
          static class A {
              void f(Box<?> box) {}
          }
          static class B extends A {
              void f(Box<? extends Number> box) {}
          }
      }

      class T3 { // works
          static class A {
              void f(Box<? extends Object> box) {}
          }
          static class B extends A {
              void f(Box<?> box) {}
          }
      }

      class T4 { // works
          static class A {
              void f(Box<? extends Number> box) {}
          }
          static class B extends A {
              void f(Box<?> box) {}
          }
      }

      class T5 { // fails
          static class A {
              void f(Box<? extends Object> box) {}
          }
          static class B extends A {
              void f(Box<? extends Number> box) {}
          }
      }

            dlsmith Dan Smith
            gafter Neal Gafter (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: