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

15.12.2.5: Confusion in rules for maximally specific method disambiguation

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 9
    • 5.0, 7, 8
    • specification

    Description

      JLS 15.12.2.5 fails to specify the behavior of the following test case:

      class Foo<T> {
        void m(Integer arg) {}
        void m(T arg) {}
      }

      void m1(Foo<Integer> f1, Integer i) {
        f1.m(i);
      }

      Class type Foo<Integer> has two methods with the same signature. Of course, neither is more specific than the other. Clearly, there should be an ambiguity error. The behavior in such cases is outlined as follows:

      1) If all the maximally specific methods have override-equivalent signatures, then:
        a) If exactly one of the maximally specific methods is not declared 'abstract', ...
        b) Otherwise, if all the maximally specific methods are declared 'abstract', and the signatures of all of the maximally specific methods have the same erasure, ...
      2) Otherwise, we say the method invocation is ambiguous, and a compile-time error occurs.

      There is no case 1c, for when neither 1a nor 1b are true.

      As an aside, I think "the signatures of all of the maximally specific methods have the same erasure" is redundant, per 1. That is

      "all the maximally specific methods have override-equivalent signatures"
      implies
      "the signatures of all of the maximally specific methods have the same erasure"

      Attachments

        Issue Links

          Activity

            People

              abuckley Alex Buckley
              dlsmith Dan Smith
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: