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

Ambiguity error for abstract method call is too eager

XMLWordPrintable

    • b98
    • generic
    • generic

      The following program fails to compile, because the algorithm that identifies a most specific method may require, depending on the order in which methods are considered, that for each pair of methods, one is return-type-substitutable for the other. This is more strict than the guarantee made by the inheritance rules, which is that there exists at least one method among all those that are override-equivalent that is return-type-substitutable for all the others (JLS 8.4.8.4, 9.4.1).

      public class ReturnTypeSubstitutable {

      interface A { java.io.Serializable m(); }
      interface B { Cloneable m(); }
      interface C { Object[] m(); }

      interface D extends A, B, C {}
      interface E extends C, A, B {}
      abstract class F implements A, B, C {}
      abstract class G implements C, A, B {}

      void test(D d, E e, F f, G g) {
        d.m(); // error
        e.m(); // no error
        f.m(); // error
        g.m(); // no error
      }

      }

            mcimadamore Maurizio Cimadamore
            dlsmith Dan Smith
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: