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

Compilation fails when extend and implement same method signature with generics

XMLWordPrintable

    • x86_64
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      OS:
      - Windows 10 Pro (Version: 1803) 64 bit
      - Ubuntu 18.04 LTS 64 bit

      Java:
      - 11.0.1 2018-10-16 LTS
      - 1.8.0_181

      A DESCRIPTION OF THE PROBLEM :
      I have a class, which extends a class and implements an interface. The interface has a method with a generic parameter at the method. The superclass has a method with the same signature except that the generic parameter is at the class. When I run the compiler the compilation fails with an error:
      C is not abstract and does not override abstract method getValue() in I

      The Compiler of the current eclipse version (2018-09 (4.9.0)) compiles without errors.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the sourcecode from the testcase.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Compilation is successful
      ACTUAL -
      Compilation fails with error:
      Error:(1, 8) java: C is not abstract and does not override abstract method <T>getValue() in I

      ---------- BEGIN SOURCE ----------
      public interface I {
        <T> T getValue();
      }

      public abstract class AC<T> {
        public T getValue() { return null; }
      }

      public class C extends AC<Integer> implements I {
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      You can move the generic Parameter from the method in the interface to the Interface:

      public interface I<T> {
        T getValue();
      }

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

              Created:
              Updated: