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

Does not override compile error overriding generic method with generic parameter

XMLWordPrintable

    • x86_64
    • generic

      A DESCRIPTION OF THE PROBLEM :
      When overriding a generic method with a generic parameter the compiler does not match the parent method. It works fine with no or not generic parameters.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Try to compile the example code. Works fine for get but not for get2.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Compile with "Note: A.java uses unchecked or unsafe operations." (for get and get2)
      ACTUAL -
      error: A.B is not abstract and does not override abstract method <Y>get2(Collection<String>) in A
              public class B extends A {
                     ^
        where Y is a type-variable:
          Y extends Object declared in method <Y>get2(Collection<String>)
      A.java:21: error: name clash: get2(Collection<String>) in A.B and <Y>get2(Collection<String>) in A have the same erasure, yet neither overrides the other
                      public R<Double> get2(Collection<String> p) {
                                       ^
        where Y is a type-variable:
          Y extends Object declared in method <Y>get2(Collection<String>)
      A.java:20: error: method does not override or implement a method from a supertype
                      @Override
                      ^
      Note: A.java uses unchecked or unsafe operations.
      Note: Recompile with -Xlint:unchecked for details.
      3 errors

      ---------- BEGIN SOURCE ----------
      import java.util.Collection;

      public abstract class A {

      public abstract class R<T> { }

      public abstract <X> R<X> get(String p);

      public abstract <Y> R<Y> get2(Collection<String> p);

      public class B extends A {

      @Override
      public R<String> get(String p) {
      return null;
      }

      @Override
      public R<Double> get2(Collection<String> p) {
      return null;
      }
      }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


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

              Created:
              Updated:
              Resolved: