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

Most specific: spurious ambiguity error between abstract and default method

    XMLWordPrintable

Details

    Description

      There is a bug with most specific and default methods when two signatures are merged from a interface as a result of generic specialization:

      class Test {
          public void testMergeAbstract(DA<String> da) {
              da.m("");
          }

          public void testMergeInterface(DI<String> di) {
              di.m("");
          }

          abstract class DA<T> {
            abstract int m(T arg);
            int m(String arg) { return 42; }
          }

          interface DI<T> {
            int m(T arg);
            default int m(String arg) { return 42; }
          }
      }


      This gives:

      Test.java:234: error: reference to m is ambiguous
              di.m("");
                ^
        both method m(T) in DI and method m(String) in DI match
        where T is a type-variable:
          T extends Object declared in interface DI
      1 error

      Note that the dual case with abstract classes work just fine.

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: