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

Unambiguous method calls flagged as ambiguous

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      The following example does not compile:

      interface I1 {
          Integer m1();
      }

      interface I2 {
          Comparable<?> m1();
      }

      abstract class C implements I1, I2 {
          void test(C c) {
              c.m1(); // javac claims this call is ambigious
          }
      }

      The relevant part of JLS (excerpt from 15.12.2.5):

      If all the maximally specific methods have override-equivalent
      (8.4.2) signatures, then:

      * If exactly one of the maximally specific methods is not declared
        abstract, it is the most specific method.

      * Otherwise, if all the maximally specific methods are declared
        abstract, and the signatures of all of the maximally specific
        methods have the same erasure (4.6), then the most specific
        method is chosen arbitrarily among the subset of the maximally
        specific methods that have the most specific return type. However,
        the most specific method is considered to throw a checked exception
        if and only if that exception or its erasure is declared in the
        throws clauses of each of the maximally specific methods.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                mcimadamore Maurizio Cimadamore
                Reporter:
                ahe Peter Ahe
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: