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

<X super T> void bar1(Class<X> x) does not compile

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • 5.0
    • 5.0
    • tools
    • x86
    • windows_2000

      FULL PRODUCT VERSION :
      java version "1.5.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
      Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows 2000
      5.00.2195
      Service Pack 4

      A DESCRIPTION OF THE PROBLEM :
      Super does not seem able to accept a named parameter type... method bar4() below does not compile.

      public class Foo<T> {
              // These are all OK
              void bar1(Class<? extends T> x) {}
              <X extends T> void bar2(Class<X> x) {}
              void bar3(Class<? super T> x) {}

              // but this one causes javac to complain... why?
              <X super T> void bar4(Class<X> x) {}

              public static void main(String[] args) {
                      Foo<Number> f = new Foo<Number>();
                      f.bar1(Integer.class);
                      f.bar2(Double.class);
                      f.bar3(Object.class);
              }
      }

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Try to compile code snippet above, see error.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      expected it to compile, and for <X super T> to work similarly to <X extends T>
      ACTUAL -
      won't compile


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Foo.java:8: > expected
              <X super T> void bar4(Class<X> x) {}
                 ^
      Foo.java:12: illegal start of type
                      f.bar1(Integer.class);
                                     ^

      etc.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class Foo<T> {
              // These are all OK
              void bar1(Class<? extends T> x) {}
              <X extends T> void bar2(Class<X> x) {}
              void bar3(Class<? super T> x) {}

              // but this one causes javac to complain... why?
              <X super T> void bar4(Class<X> x) {}

              public static void main(String[] args) {
                      Foo<Number> f = new Foo<Number>();
                      f.bar1(Integer.class);
                      f.bar2(Double.class);
                      f.bar3(Object.class);
              }
      }
      ---------- END SOURCE ----------
      ###@###.### 10/21/04 17:04 GMT

            Unassigned Unassigned
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: