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

Overriding generic method fails

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • None
    • 6u23
    • tools
    • x86
    • windows_vista

      FULL PRODUCT VERSION :
      java version "1.6.0_23"
      Java(TM) SE Runtime Environment (build 1.6.0_23-b05)
      Java HotSpot(TM) Client VM (build 19.0-b09, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.0.6002]

      A DESCRIPTION OF THE PROBLEM :
      In the the attached example class Impl attempts to implement generic method work() declared in interface Algo.
      javac fails to compile it.

      I believe that the code is correct.
      Furthermore, if fake type parameter is added to work(), javac compiles the code just fine.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the example.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Compilation should succeed.
      ACTUAL -
      Compilation fails.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Impl.java:1: Impl is not abstract and does not override abstract method <V>work(V,X) in Algo
      public class Impl<X> implements Algo<X> {
             ^
      Impl.java:2: method does not override or implement a method from a supertype
          @Override
          ^
      2 errors

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public interface Val<V extends Val<V, X>, X> {
          V add(V v);

          X x();
      }

      public interface Algo<X> {
          <V extends Val<V, X>>
          V work(V v, X x);
      }

      public class Impl<X> implements Algo<X> {
          @Override
          public <V extends Val<V, X>>
          V work(V v, X x) {
              return v;
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Add fake type parameter W to work():

      public interface Algo<X> {
          <V extends Val<V, X>, W>
          V work(V v, X x);
      }

      public class Impl<X> implements Algo<X> {
          @Override
          public <V extends Val<V, X>, W>
          V work(V v, X x) {
              return v;
          }
      }

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: